Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Assign dataset computed field value to global variable
iffizin
Hi,
i want to assign dataset field value to global variable. my dataset has computed colum, which i want to store in global variable. i tried following code
reportContext.getPersistentGlobalVariable("myvalue", this.getRowData().getColumnValue("ITMthreshold"))
but failed with error.
thx
Find more posts tagged with
Comments
mwilliams
Hi Iffizin,
To create a global variable, you'll need to use the setPersistentGlobalVariable function. To retrieve it later you'll use the getPersistentGlobalVariable function.
kevinshih
Hi Michael,
I tried the example you gave above, but get an error. The code I use in the onFetch() method of the dataset is:
reportContext.setGlobalVariable("resourceInterfaceList", this.getRowData().getColumnValue("FIELD_NAME"));
The error I get is:
Caused by: org.eclipse.birt.data.engine.core.DataException: A BIRT exception occurred: There are errors evaluating script "__bm_onFetch()":TypeError: Cannot find function getRowData. (<inline>#2).. See next exception for more information.There are errors evaluating script "__bm_onFetch()":TypeError: Cannot find function getRowData. (<inline>#2). at org.eclipse.birt.data.engine.core.DataException.wrap(DataException.java:118) at org.eclipse.birt.data.engine.script.ScriptEvalUtil.evaluateJSAsExpr(ScriptEvalUtil.java:717) at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:76) at org.eclipse.birt.report.engine.script.internal.DtEScriptExecutor.handleJS(DtEScriptExecutor.java:71) ... 98 moreCaused by: org.eclipse.birt.core.exception.CoreException: There are errors evaluating script "__bm_onFetch()":TypeError: Cannot find function getRowData. (<inline>#2). at org.eclipse.birt.core.script.ScriptContext.eval(ScriptContext.java:307) at org.eclipse.birt.core.script.ScriptContext.eval(ScriptContext.java:268) at org.eclipse.birt.data.engine.script.ScriptEvalUtil.evaluateJSAsExpr(ScriptEvalUtil.java:713) ... 100 moreCaused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function getRowData. (<inline>#2)
I am using Birt 2.3.2.
Thanks,
Kevin
kevinshih
Hi Michael,
Also tried this in the onFetch() method:
reportContext.setGlobalVariable("resourceInterfaceList", row["resourceInterfaceList"]);
but the variable comes back null when I call it later in the report
chorton
Any updates on this? I'm having the same issue. Can't get a value from the data set into a global variable.
mwilliams
Hi chorton,
Are you using just globalVariable or persistentGlobalVariable? And where are you having this issue? Can you explain more? Thanks.
chorton
Sorry, I created a new post before I realized you commented on this one.
Here's the content from the other post:
"
This is what I have in the initialize method of the report.
reportContext.setPersistentGlobalVariable("BeginningBalance", 5);
This is what I have in the onCreate method of a label element.
reportContext.getPersistentGlobalVariable("BeginningBalance");
Doesn't work."
mwilliams
I went ahead and answered in the other thread. Let me know in there if what I said works for you.<br />
<br />
Link to other thread:<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/forum/designing-birt-reports/19531-trouble-persistent-variables.html'>http://www.birt-exchange.org/forum/designing-birt-reports/19531-trouble-persistent-variables.html</a>
;
rk1981
<p>Hello,</p>
<p>I have problems with global variables, I have a chart and a grid and i am programming in the script</p>
<p>In the grid script I have this ----> reportContext.setPersistentGlobalVariable("row[A_UNIT_VAL]",max)</p>
<p> </p>
<p>and in the chart script i have this ---> </p>
<p><b>function</b> beforeDrawLegendItem( lerh, bounds, icsc )</p>
<p>{</p>
<p> </p>
<p><b>var</b> max = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("max");</p>
<p><b>var</b> x = lerh.getLabel().getCaption().getValue(); </p>
<p> </p>
<p> </p>
<p> </p>
<p>lerh.getLabel().getCaption().setValue(x + " " + max);</p>
<p> </p>
<p>}</p>
<p> </p>
<p>but the value always is null, row[A_UNIT_VAL] represents a excel column with the same number</p>
<p> </p>
<p>i hope that you can help me</p>
Clement Wong
<p>rk1981,</p>
<p> </p>
<p>It looks like your syntax to set the PGV is not correct. It should be swapped like this: </p>
<pre class="_prettyXprint">
reportContext.setPersistentGlobalVariable (name_of_variable,value_of_variable);</pre>
<p>Also, I'm not sure where you are trying to set the PGV to get the value of the column A_UNIT_VAL. For example, if it's in the onCreate, you may need to use this syntax to access the row's column value:</p>
<pre class="_prettyXprint">
var theColumnValue = this.getRowData().getColumnValue("A_UNIT_VAL");
</pre>