davejal
davejal

Reputation: 6133

How to send multiple variables using birt report?

Using the following query in db2:

select * from table where num in ('1a2334','1a43432','1a34243','1b34325','1b4545')

Now whenever I get data to report I get the rows like from the users:

1a23344
1a43432
1a34243
1b34325
1b45454

Then I use notepad++ to replace rf with ',' so it becomes

'1a2334','1a43432','1a34243','1b34325','1b4545'

What are my options for creating a report that accepts input easy enough for the average user?

This specific user has an excel sheet with multiple columns, I only use the first column (the mentioned examples above are rows from the first column).

A good solution provided by @Simulant, but I need this to get values from an excel file (preferably by copy paste). I noticed his/her solution uses static values, so I think I need dynamic values. For the record I got the following error using the script:

Error evaluating Javascript expression. Script engine error: TypeError: Cannot call method "replace" of null (/report/data-sets/script-data-set[@id="12"]/method[@name="beforeOpen"]#3) Script source: /report/data-sets/script-data-set[@id="12"]/method[@name="beforeOpen"], line: 0, text: __bm_beforeOpen(). (Element ID:1) Error.ScriptEvaluationError ( 1 time(s) ) detail : org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script "var parameters = params["multiSelectParameter"].value; var replacesPart = "'" + parameters.join("', '") + "'"; this.queryText = this.queryText.replace("replaceMe", replacesPart);":

Upvotes: 1

Views: 2574

Answers (1)

Simulant
Simulant

Reputation: 20112

Create a Report with a Multi-Select Parameter. Create a List Box Parameter and allow multiple values. You can add static values or select dynamic and display the result of another query.

enter image description here

Write your query as following SQL-Statement:

select * from table where num in (replaceMe);

Select your Data-Set and select the script Tab. Enter for the beforeOpen the following script. This replaces the placeholder replaceMe in your SQL-Statement with the concatinated values of your Multi-Select Parameter enclosed with single quotes ' and separated with commas , as you need it:

var parameters = params["multiSelectParameter"].value;
var replacesPart = "'" + parameters.join("', '") + "'";
this.queryText = this.queryText.replace("replaceMe", replacesPart);

Upvotes: 3

Related Questions