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)
PersistentGlobalVariable
TheRealDea
Can I:
Create a Persistent Global Variable(PGV) in OnFetch of a dataset,
Then, reference the PGV in a Data element expression?
Find more posts tagged with
Comments
mwilliams
Hi TheRealDea,
I believe you should be able to do so. I have not tried it yet though. Have you? What exactly are you trying to do? Let me know. Thanks.
CBR
Yes that's possible. You have to keep in mind that your variable is set in onFetch method the time the first element of your report occurs that s bound to that data set. So it's possible that you reference the variable before it is initialized.<br />
<br />
For your needs a global variable should be sufficient.<br />
A global persistent variable is persistent accross the report generation phases (Run&Render). Have a look at: <a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/deploy/reportScripting.php'>Report
Scripting</a> for the BIRT generation model and informations about global persistent variables.
TheRealDea
Would it be better than to initialize the GPV in the Initialize method of the report? What I am trying to accomplish, is to use a Grid with some columns, and finally a totals column. There will be 3 columns. The first 2 have dataset/tables, and a summation in their respective footers. Then, I need to get those summations to total into the 3rd column as a row total.
I choose a Grid since each table/dataset exist seperately, yet I could control their appearance.
GRID
table1 table2 total
(total1) (total2) (total1+total2)
mwilliams
TheRealDea,
Is there no common key between the two dataSets to join them, so you can do all your calculations in a single table?
TheRealDea
I think you may have hit on something for me. I will work on that; however, is it possible still yet to populate a GPV in the OnFetch method, and then retrieve that value from a Data control?
mwilliams
TheRealDea,
The onFetch runs for each row in the dataSet, so to set PGV's there, you'd have to name them based on a key value to be able to recall them for your third column something like below.
In dataSet1:
reportContext.setPersistentGlobalVariable(row["key"] + "1", row["value"]);
In dataSet2:
reportContext.setPersistentGlobalVariable(row["key"] + "2", row["value"]);
The 1 & 2 added to the PGV name to separate them since they're for the same key. Otherwise the first value would be overwritten before you were able to recall it.
TheRealDea
I had started:
In dataSet1:
var curr = row["beginBal"];
reportContext.setPersistentGlobalVariable("beginBal1", curr);
Would this work? Should I initialize the PGV in the report/initialize event - for proper programming style.
Ideally, I see this PGV being populated before the grid is built. Is so, then I was using a Data control to display the value. What would be the proper syntax to retreive the PGV, because I seem to recall having issues with
reportContext.getPersistentGlobalVariable("beginBal1");.
Again, thank you for taking the time to help me through this.
mwilliams
TheRealDea,
That looks like it should work. Can you build a similar setup to what you're trying to do with the sample database? It may make it easier to help if we can pass a report back and forth. If you do, let me know what version of BIRT you're using. Thanks.
TheRealDea
Version 3.2.3
I have placed three scripts in the rptDesign
mwilliams
What version of BIRT is that? BIRT 2.2.0, I'm guessing?
Edit - Nevermind...just opened your design in 2.2, it's BIRT 2.5.1. Alright, I'll take a look.
mwilliams
TheRealDea,
Take a look at the changes I made to your report and script. Let me know if you have any questions.