Jump to content
We've recently updated our Privacy Statement, available here ×

Is it possible to use optional filters in a domain based report?


javier.ggi90
Go to solution Solved by javier.ggi90,

Recommended Posts

Hi all, so I need to do something like this: filter a report by ID if the user passes it along but show all data in the user leaves this blank. I have tried several approaches, including:

  1. Making a parameter a whole string and using that as a single filter, but I get errors when running the report.
  2. Making a kind of boolean operations as this: (FIELD == Parameter or ParameterBool == 1) where ParameterBool will be 1 if Parameter is null and 0 if not null. This also gives errors when running.

Anyone knows a way to achieve this?

 

Thanks,

Javier

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

I'm not sure if using the $P!{variable_name} syntax works with domain reports. Personally, I found "Filter expressions" to be good for these situations.

Suppose I have a report listing all events. have an optional parameter called "Type". If the user specifies the type, then it gets filtered, otherwise it will display all results.

If using iReport or Jaspersoft Studio, under the "Filter Expression" section, enter

($P{Type}!=null?($F{events.eventType}.contains($P{Type})):Boolean.TRUE)[/code]

The generic format is

($P{PARAMETER_NAME}!=null?($F{DATABASE_FIELD_NAME}.contains($P{PARAMERER_NAME})):Boolean.TRUE)[/code]

 

This will check if any value is specified in the parameter. If not, it will display all records unfiltered. If a value is specified, then it filters to only that value.

 

Hope it helps.

Link to comment
Share on other sites

  • Solution

I did not know anything about filter expressions, good to know they are there and I can try them next time so thanks for the info Wayne.

I found a "solution", I used the following:

(FIELD == Parameter or ParameterBool == 1) and (FIELD2 == Parameter2 or ParameterBool2 == 1) and ... (FIELDn == Parametern or ParameterBooln == 1)

This is something I had tried before but got errors, the catch is that this does not work in Studio or iReport, it has to be run directly in the server which I had not done before.

 

Javier

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...