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)
Evaluate Birt report params in regex
Baki DJ
Hi,<br />
<br />
I've created report with one string parameter named pUsername<br />
<br />
<br />
data set query look like <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>select *
from users
where (users.username = :pUsername or :pUsername = 'admin')</pre>
<br />
to avoid using dataset parameters and mulitple usage of ?<br />
<br />
I've created dataset script on beforeOpen<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>this.queryText = this.queryText.replaceAll(":pUsername", params["pUsername"]);</pre>
<br />
and it works, but i want make more general solution when query contains couple params.<br />
<br />
When I chage code beforeOpen data set to<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>this.queryText = this.queryText.replaceAll(":(\\w*)", params["$1"]);</pre>
<br />
Expression fails and also<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>this.queryText = this.queryText.replaceAll(":(\\w*)", "params[\"$1\"]");</pre>
<br />
parameter expression is not evaluated and query fails.<br />
<br />
<br />
If I could use something like Eval(params["$1"]) in expresson above, it will bee great.<br />
<br />
Baki<br />
<br />
Thanks
Find more posts tagged with
Comments
Clement Wong
To access the first parameter (zero based index), you can use the expression:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>params[reportContext.getDesignHandle().getAllParameters().get(0).getName()];</pre>
<br />
So in your code example, it would be like this (for the first parameter):<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>this.queryText = this.queryText.replaceAll(":(\\w*)", params[reportContext.getDesignHandle().getAllParameters().get(0).getName()]);</pre>