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)
Best way to initialize variable from Scripted Data Set
petr.mensk
Hello, I have three incoming context parameters - List, Date and Date. So in open event of data set I do something like this
iterator = taskReportList.iterator();
fromDate = dateFrom;
toDate = dateTo;
//or save somewhere the date values?
and in fetch event I iterate through the list items
if(iterator.hasNext()) {
var taskReport = iterator.next();
//blablabla
return true;
} else {
//save somewhere the date values
//vars["fromDate"] = fromDate or array[0] = fromDate?
return false;
}
The thing is, I need to display these two values in the report and I don't know how. I tried to create two report variables but I get always null when the values are displayed (both in Data and Dynamic Text element). I also tried to create array for the dates in initialize event of report and then just access it in element(again, both Data and Dynamic Text) but I am getting null too. But when I debug the report, both array and report variable seems to have correct value during fetch event. So can anybody please tell what is going on?
Find more posts tagged with
Comments
kclark
Set the variables as PersistentGlobalVariable<br />
<br />
beforeFactory():<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
reportContext.setPersistentGlobalVariable("globalVarName", /*some data/*);
</pre>
<br />
beforeRender():<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
reportContext.getDesignHandle().getElementByID(27).text = reportContext.getPersistentGlobalVariable("globalVar");
</pre>
petr.mensk
Thanks for answer but this doesn't work for me. Even when I try <br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
reportContext.getDesignHandle().getElementByID(226).text = "text";
</pre>
<br />
where 226 is id of my Dynamic Text. It still gives me original value of Dynamic Text (or null if I don't have anything in Dynanmic Text element).
kclark
What method are you calling that code from?
petr.mensk
beforeRender as you suggested.
kclark
It was my mistake, use
reportContext.getPersistentGlobalVariable("globalVar");
inside of your dynamic text and it should show up.
petr.mensk
Thanks for example, it works great, but I need to make this work with Scripted Data Set. In another words, I want to run this in fetch event of my Data Set with parameter coming from our application. When I write<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
reportContext.setPersistentGlobalVariable("toDate", toDate);
Packages.java.lang.System.out.println("message " + reportContext.getPersistentGlobalVariable("toDate"));
</pre>
the value is printed correctly. But when I try to access it in Dynamic Text I get empty string. <br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
reportContext.getPersistentGlobalVariable("toDate");
</pre>
So am I doing anything wrong?