Home
Analytics
How to set filter on dataset dynamically?
lazeeboy
I would like to know to filter a dataset based on values passed in via report parameters.
The parameters to the report are stored in DB and are as below
'ABC', 'PQR', 'XYZ'. All are string values seprated by comma. What type of parameter should i set up in the report and how to dynamically set the fitler condition.
I tried the following but it did not help
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.elements);
reportContext.getReportRunnable().designHandle.getDesignHandle().findDataSet("TransactionSupplementID");
dshandle = reportContext.getReportRunnable().designHandle.getDesignHandle().getDataSets().get(0);
var book = new Array();
book[0] = 'ABC';
book[1] = 'XYZ;
fc = StructureFactory.createFilterCond();
fc.setExpr("dataSetRow["BookCode"]");
fc.setOperator(DesignChoiceConstants.MAP_OPERATOR_EQ);
fc.setValue1( """ + book[0] + """);
dshandle.addFilter(fc);
Any help would be much appreciated
ashish
Find more posts tagged with
Comments
mwilliams
Hi ashish,
So, you pass your parameters into the report through a report parameter and they are listed as follows in a single text box parameter?
'ABC', 'PQR', 'XYZ'
Then, you want to use these values to filter the dataSet if listed in the report parameter? Is this correct? Or am I missing something?
lazeeboy
Michael,
You are correct? The parameter values are stored in db table as
'ABC','PQR','XYZ' and the report parameter is a text box. I want to then filter the dataset based on these parameter values.
e.g
DataSet
Book BookName
ABC Book of ABC
PQR Book of PQR
XYZ Book of XYZ
MNO Book of MNO
Therefore if my parameter is set as 'ABC', 'PQR' then only two records should be filtered out
ashish
mwilliams
ashish,
If I'm understanding correctly. If you're using an SQL dataSet, you could use the IN clause in your query. Otherwise, you should be able to use a filter with the "IN" option as the function for the filter, something like:
row["Book"] IN params["paramName"]
If your dataSet is as above and a parameter box pops up and values are entered as 'ABC','MNO', you may have to step through the parameter string and remove the single quotes for it to work. Let me know if I'm misunderstanding.
lazeeboy
Michael,
The Dataset is based on a Stored procedure. I tried to use the filter property on the dataset row["BookCode"] in '<value1>';'<value2>'. This works but if you replace the '<value1>';'<value2>' with param["pbook"] where it is set as 'HCZA';'LEFS' it does not work.
mwilliams
lazeeboy,
What version of BIRT are you using? I'll set up an example using a text box parameter with multiple values listed in a filter and post it in here.
lazeeboy
Michael,
I m using Actuate BIRT 2.2.2
Thanks for the help
Regards,
ashish