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)
set and get PersistentGlobalVariable
Arco
Hi there,
I'm running into some troubles using set and get PersistentGlobalVariable.
I'm setting the variable in the onFetch event of the dataset and try to get it in the onRender of a text element.
When I set the variable with "reportContext.setPersistentGlobalVariable('state',row['STATE']);"
and get it with
"var state = reportContext.getPersistentGlobalVariable('state');
this.text = state;"
this works fine.
But actually I want to save the whole record instead of just the state so I changed the code to.
"reportContext.setPersistentGlobalVariable('customer',row);"
"var customer = reportContext.getPersistentGlobalVariable('customer');
this.text = customer['STATE'];"
For some reason this doesn't work, the text field is empty.
Can anyone explain why this is happening or tell me how to solve this?
Thanks in advance,
Arco
Find more posts tagged with
Comments
mwilliams
Hi Arco,
I believe a PGV stores a string, not an object, so you probably won't be able to pass the row object this way. You'll have to just make different PGV's for each field in the row or create a comma separated string of the values of the row, pass them through the PGV, split the string into a string array and access them that way.
Hope this helps.
Arco
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="67485" data-time="1282144129" data-date="18 August 2010 - 08:08 AM"><p>
Hi Arco,<br />
<br />
I believe a PGV stores a string, not an object, so you probably won't be able to pass the row object this way. You'll have to just make different PGV's for each field in the row or create a comma separated string of the values of the row, pass them through the PGV, split the string into a string array and access them that way.<br />
<br />
Hope this helps.<br /></p></blockquote>
<br />
I don't think you can store a string only.<br />
The documentation says an object can be stored so this should work in my opinion.<br />
See this link:<br />
<a class='bbc_url' href='
http://www.birt-exchange.com/be/documentation/BIRT_220/EngineJavadoc/enginescript/api/org/eclipse/birt/report/engine/api/script/IReportContext.html#setPersistentGlobalVariable(java.lang.String'>http://www.birt-exchange.com/be/documentation/BIRT_220/EngineJavadoc/enginescript/api/org/eclipse/birt/report/engine/api/script/IReportContext.html#setPersistentGlobalVariable(java.lang.String</a>
, java.io.Serializable)
mwilliams
Arco,
I've seen that and have always been confused by it, but I've only ever seen it be successful by passing a string and I guess have accepted it to only work with strings. I'll look into passing an object through and let you know what I find. It should definitely work in the ways I said above though.
pricher
For the record, you can store Maps or Arrays in Persistent Global variables. For example:
Storing done in onCreate:
var map = new java.util.HashMap();
map.put("STRING", "String in a Hashmap");
map.put("NUMBER", 500);
map.put("DATE", new Date());
var array = new java.util.ArrayList();
array.add("String in an Array");
array.add(500);
array.add(new Date());
reportContext.setPersistentGlobalVariable("array", array);
reportContext.setPersistentGlobalVariable("map", map);
Retrieving of HashMap done in onRender:
var map = reportContext.getPersistentGlobalVariable("map");
this.text = map.get("STRING");
Retrieving of arrays done in onRender:
var array = reportContext.getPersistentGlobalVariable("array");
this.text = array.get(0);
This doesn't solve the initial question, but I thought I would clarify the String vs. Object issue.
P.
mwilliams
Thanks for the info P! I had just set up the array object and done it, so that does work. Arco, I'll mess around with and research the row object with a PGV now and see what I find out. I'll let you know if I find anything other than it doesn't work.
However, there are now several different ways that something similar to what you're wanting can be achieved, so either way there should be a way to get what you're wanting done!
Arco
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="67493" data-time="1282159599" data-date="18 August 2010 - 12:26 PM"><p>
Thanks for the info P! I had just set up the array object and done it, so that does work. Arco, I'll mess around with and research the row object with a PGV now and see what I find out. I'll let you know if I find anything other than it doesn't work.
However, there are now several different ways that something similar to what you're wanting can be achieved, so either way there should be a way to get what you're wanting done!<br /></p></blockquote>
Michael,<br />
<br />
You're right but the disadvantage of the solutions is I have to add all columns one by one so it would be nice if I can store the whole record at once.<br />
In the meantime I found out that the object being returned from the store is of type org.eclipse.birt.data.engine.script.JSRowObject so something is stored, the question is how to get the column values from this object.
mwilliams
I passed "this" through the PGV from the onCreate of a table row and was able to grab the column names, but not the value. I have been unable to pass "row" through from the dataSet though. You could add the column values to an array dynamically by using the column count to cycle through the row and add each value to the array. If I find anything else out on the "row", I'll post it. You might log a bug on it just to see if they come back with something that tells you how to do so.
Arco
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="67538" data-time="1282238448" data-date="19 August 2010 - 10:20 AM"><p>
I passed "this" through the PGV from the onCreate of a table row and was able to grab the column names, but not the value. I have been unable to pass "row" through from the dataSet though. You could add the column values to an array dynamically by using the column count to cycle through the row and add each value to the array. If I find anything else out on the "row", I'll post it. You might log a bug on it just to see if they come back with something that tells you how to do so.<br /></p></blockquote>
Hi Michael,<br />
<br />
Thanks for your reply and time you spend on this.<br />
Since I'm quit new on BIRT and this community can tell me how to log a bug ?<br />
Thanks in advance,<br />
Arco
mwilliams
Arco,
My mistake. I should have posted the link before. Here ya go:
http://www.birt-exchange.org/org/resources/bug-reporting/
If you don't mind, please post the bug info in here so if anyone else with this issue stumbles upon this thread, they can see it. Thanks!
Arco
Created a bug report:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=323366
mwilliams
Arco,
Thanks for the update!
virgosmart
<p>Hello,</p><p> </p><p>Is there a way to setup a map with data from the data set, say on the "onCreate" event of a row of an invisible table and to later use the data thus stored in the map in another table ? The reason for this is that the layout of the result set varies from the report layout.</p><p> </p><p>I observed that only if the map is setup in the "initialize" event of the report, will it be available in the other "onCreate" event of the other table.</p><p> </p><p>Regards,</p><p>Gautam.</p>
mwilliams
<p>One thing you could do would be to use a hidden element bound to your first dataset to get the dataset to run, then use the onFetch method of the dataset to grab the data and store it in arrays or whatever you'd like, then, create a scripted dataset using the data, however you'd like. Then, you could just use this new, scripted dataset for your second table.</p>