Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Multi-Select Listbox handling for batch reports
rpolunsky
The multi-value listbox parameter type is very handy for interactive reporting, but if you want to invoke that report in a batch process (such as using genReport.bat) or programmatically (via URL), you run into a major problem. BIRT does not have a command-line/URL-based syntax for passing multi-value parameter selections. The listbox parameter implements as an Object[], which is the source of much grief in this situation. However, it turns out that the ToString() method on that Object yields a comma-separated list - and that I can work with.
I have a workaround approach that seems to be working for me.
I create a parallel parameter, type string. Call the listbox MultiValue and the parallel parameter MultiValue_CSV. Now I determine whether the string parameter is nonempty and if so I ignore the value in the listbox.
In my report initialize event I have the following:
// MultiValue is a multiselect listbox, required; MultiValue_CSV is a textbox, not required, no default
var valuelist = params["MultiValue"].toString();
var staticlist;
reportContext.setPersistentGlobalVariable("listbox_value", valuelist);
reportContext.setPersistentGlobalVariable("filter_list", valuelist);
if (null == params["MultiValue_CSV"].value) {
reportContext.setPersistentGlobalVariable("override_value", "is null");
} else {
reportContext.setPersistentGlobalVariable("override_value", "not null");
staticlist = params["MultiValue_CSV"].value;
if (staticlist.length > 0) {
reportContext.setPersistentGlobalVariable("override_text", staticlist);
reportContext.setPersistentGlobalVariable("filter_list", staticlist);
} else {
reportContext.setPersistentGlobalVariable("override_text", "empty string");
};
};
The relevant value is held in the gloval variable "filter_list".
Finally, my dataset query is defined with a where clause like
" AND Alloc_ID IN (0) "
Then, in the beforeOpen event of the dataset, I make the following substitution:
this.queryText = this.queryText.replace("(0)", "(" + reportContext.getPersistentGlobalVariable("filter_list") + ")");
I'm swamped right now, but I'll try and get something whipped up this month against the Derby database to make a sample report available.
Find more posts tagged with
Comments
johnw
Thats awesome. Put this together and submit it to the DevShare. They have upped the prizes for winners, and this is definitely a contender. I'd get it done quick though, I'm considering stealing this for myself, so someone else might
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'rpolunsky'" data-cid="69315" data-time="1286988608" data-date="13 October 2010 - 09:50 AM"><p>
The multi-value listbox parameter type is very handy for interactive reporting, but if you want to invoke that report in a batch process (such as using genReport.bat) or programmatically (via URL), you run into a major problem. BIRT does not have a command-line/URL-based syntax for passing multi-value parameter selections. The listbox parameter implements as an Object[], which is the source of much grief in this situation. However, it turns out that the ToString() method on that Object yields a comma-separated list - and that I can work with.<br />
<br />
I have a workaround approach that seems to be working for me.<br />
<br />
I create a parallel parameter, type string. Call the listbox MultiValue and the parallel parameter MultiValue_CSV. Now I determine whether the string parameter is nonempty and if so I ignore the value in the listbox.<br />
<br />
In my report initialize event I have the following:<br />
<br />
// MultiValue is a multiselect listbox, required; MultiValue_CSV is a textbox, not required, no default<br />
var valuelist = params["MultiValue"].toString();<br />
var staticlist;<br />
reportContext.setPersistentGlobalVariable("listbox_value", valuelist);<br />
reportContext.setPersistentGlobalVariable("filter_list", valuelist);<br />
if (null == params["MultiValue_CSV"].value) {<br />
reportContext.setPersistentGlobalVariable("override_value", "is null");<br />
} else {<br />
reportContext.setPersistentGlobalVariable("override_value", "not null");<br />
staticlist = params["MultiValue_CSV"].value;<br />
if (staticlist.length > 0) {<br />
reportContext.setPersistentGlobalVariable("override_text", staticlist);<br />
reportContext.setPersistentGlobalVariable("filter_list", staticlist);<br />
} else {<br />
reportContext.setPersistentGlobalVariable("override_text", "empty string");<br />
};<br />
};<br />
<br />
The relevant value is held in the gloval variable "filter_list".<br />
<br />
Finally, my dataset query is defined with a where clause like<br />
" AND Alloc_ID IN (0) "<br />
<br />
Then, in the beforeOpen event of the dataset, I make the following substitution:<br />
<br />
this.queryText = this.queryText.replace("(0)", "(" + reportContext.getPersistentGlobalVariable("filter_list") + ")");<br />
<br />
I'm swamped right now, but I'll try and get something whipped up this month against the Derby database to make a sample report available.<br /></p></blockquote>
birtprofi
Hi,
sounds good. Please come back at this topic with a sample report.
regards
rafael