Home
Analytics
How to populate array dynamically from BIRT Dataset and store array in reportContext PGV
sarmistha_birt
<p><span style="font-size:medium;">[font="calibri;"]Hi,[/font]</span></p><p> </p><p><span style="font-size:medium;">[font="calibri;"]I am working on BIRT v2.6.1 (open source reporting tool from eclipse) and I have the following requirement:[/font]</span></p><p> </p><p><span style="font-size:medium;">[font="calibri;"]I have to populate an array dynamically based on the data retrieved from one “BIRT Data Set†and once the array is populated, I need to store the array in the “reportcontext†as a PersistentGlobalVariable.[/font]</span></p><p><span style="font-size:medium;">[font="calibri;"]And in another “BIRT Data Setâ€, I have to retrieve the array from the “reportcontext†using “<strong>[color=rgb(75,172,198);]reportContext.getPersistentGlobalVariable("myArray");â€[/color]</strong>[/font]</span></p><p> </p><p><span style="font-size:medium;">[font="calibri;"]This is what I have done:[/font]</span></p><p><span style="font-size:medium;">[font="calibri;"]I have a dataset named <strong>[color=rgb(75,172,198);]“Library Data Setâ€.[/color]</strong>[/font] The query for the dataset is <strong>[color=rgb(75,172,198);]“SELECT LIBRARY_ID FROM TABLE1â€.[/color]</strong></span></p><ul class='bbc'><li><span style="font-size:medium;">[font="calibri;"]In the “Library Data Setâ€->beforeOpen event, I have written the following code:[/font]</span></li></ul><p><strong>[color=rgb(75,172,198);]<span style="font-size:medium;">[font="calibri;"]idx=0;[/color][/font]</span></strong></p><p><strong>[color=rgb(75,172,198);]<span style="font-size:medium;">[font="calibri;"]myArray=[];[/color][/font]</span></strong></p><ul class='bbc'><li><span style="font-size:medium;">[font="calibri;"]In the “Library Data Setâ€->onFetch event, I have written the following code:[/font]</span></li></ul><p><strong>[color=rgb(75,172,198);]<span style="font-size:medium;">[font="calibri;"]myArray[idx++] = row["LIBRARY_ID"];[/color][/font]</span></strong></p><ul class='bbc'><li><span style="font-size:medium;">[font="calibri;"]In the “Library Data Setâ€->beforeClose event, I have written the following code:[/font]</span></li></ul><p><strong>[color=rgb(75,172,198);]<span style="font-size:medium;">[font="calibri;"]reportContext.setPersistentGlobalVariable("myArray",myArray);[/color][/font]</span></strong></p><p> </p><p><span style="font-size:medium;">[font="calibri;"]But it I not working. [/font]</span></p><p> </p><p><span style="font-size:medium;">[font="calibri;"]Could anyone kindly help me in this regard?[/font]</span></p>
Find more posts tagged with
Comments
micajblock
<p>What is the business requirement you are trying to fulfill? Why do you need to fill a data set with values form another data set?</p>
sarmistha_birt
<p>Hi,</p><p> </p><p>Many thanks for responding.</p><p> </p><p>The requirement is to display the data from ALL Libraries in one single report.</p><p> </p><p>Now in database, the table name for each library is like "TABLE_<LibrayNumber>".</p><p> </p><p>So baically I will have to do a UNION of all tables. For example if there are 5 libraries in the database in the LIBRARY_MASTER table, then the report query to display the data would be something like this:</p><p> </p><p>SELECT * FROM TABLE_1</p><p>UNION</p><p>SELECT * FROM TABLE_2</p><p>UNION</p><p>SELECT * FROM TABLE_3</p><p>UNION</p><p>SELECT * FROM TABLE_4</p><p>UNION</p><p>SELECT * FROM TABLE_5</p><p> </p><p>So I have created 2 Data Sets.</p><p> </p><p>1. Library Data Set (SELECT LIBRARY_ID FROM LIBRARY_MASTER).</p><p> I want to populate an array dynamically with all the LIBRARY_ID fetched from database and then want to store the array in the PGV. </p><p> </p><p>2. Result Data Set</p><p> In the beforeOpen script, I am trying to retrieve the library array from PGV.</p><p> I have written a for loop to traverse through the library array and here dynamically i am trying to create the UNION query. </p><p> </p><p>Hope I am able to explain it clearly.</p><p> </p><p>Thanks,</p><p>Sarmistha</p>
micajblock
<p>I don't think you need a persistent global variable. The issue might be that the first data set never gets executed. If there is no table that uses it, BIRT will not execute the data set. try creating a table (which you can hide) for the first data set). You can use regular variables. Maybe this video of the order of events will help you understand. </p><p> </p><p>
https://www.youtube.com/watch?v=FQ9VjByPNWM</p>
sarmistha_birt
Actually the Library dataset is getting executed. I am saying this because the same library data set is being used in the list box that I have for one of the report input parameters.
The library id report input parameter is a list box which fetches the library ids using the library data set and I am able to see all library ids in that drop down.
Pulak Bose
<p>You might want to change the array to an arraylist and check whether it works.</p><p> </p><p>Refer to this thread, to get an understanding of the PGV and the related events.</p><p> </p><p><a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/20312-set-and-get-persistentglobalvariable/'>http://developer.actuate.com/community/forum/index.php?/topic/20312-set-and-get-persistentglobalvariable/</a></p>
;
sarmistha_birt
Hi Pulak,
Could you kindly let me know on which event I should write the code to populate the arraylist.also could you kindly share the syntax.i have tried all options but it is still not working. Kindly help.thanks
sarmistha_birt
I have observed that report context is not accessible in any of the data set events (onfetch,beforeOpen,beforeClose etc.). Could anyone kindly help me in resolving my issue. I want to populate an arraylist dynamically in the onfetch event of a datasst.
Would appreciate your kind help.
Pulak Bose
<p>You can bind the dataset to a table and hide the table. Create your dynamic query in the onCreate of the table row.</p>