Filter BIRT JDBC Query

Options
kpeters
edited July 28, 2021 in Analytics #1
<p>There is a ServerUserName variable in the AppContext that gets passed to the engine tasks/report scripts. You can design a report with a parameterized JDBC query and the parameter can be bound to an expression that is a function of the ServerUserName in AppContext. Since this parameter only gets passed when it is ran on the iServer, the expression will need to check if it exists first, if yes, use it to set the JDBC query parameter value.</p>
<p>In the beforeOpen method of the data set you can access the appContext, which is a HashMap, from the report context. Get the object from the Map using the key ServerUserName. Here is sample code that illustrates how you could filter the query in the beforeOpen method:</p>
<p><span style=\"font-family: Courier New,Courier,monospace;\">
<div class=\"xoopsCode\" style=\"border: 1px solid;\">
<p><span style=\"font-family: Courier New,Courier,monospace;\">myMap = reportContext.getAppContext();<br />usr = myMap.get(\"ServerUserName\");<br />if(usr != null)<br />{ <br /> this.queryText = this.queryText + \" WHERE userid = \''\" + usr + \"\''\" <br />}</span></p>
</div>
</span></p>