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)
How to 'add elements'/'change values' outside onPrepare()?
germobirt
Hi,<br />
<br />
using Birt 2.6.2 I want with a script, <span class='bbc_underline'>manually </span>set data in grid elements outside onPrepare().<br />
<br />
I've a grid 3 cols and 40 rows.<br />
During onPrepare() of the grid I add 40 labels in the 1. col. Works!<br />
During a following script, I want to use values from a dataset and put these somehow in the grid, <br />
e.g into col 2 and set at this time styles as e.g. borders.<br />
<br />
But as I read, I can't add further labels outside onPrepare();<br />
<br />
But the onFetch() script ist running after onPrepare(), so I'll have the data to late.<br />
I put these data in a global array, but where can I reuse them for putting them in my report?<br />
<br />
1.) How can I change labels or set data to maybe "Dynamic Text" or "Data" elements in later scripts?<br />
As onCreate(), onRender(), onFetch()?<br />
<br />
2.) If I define globals vars in initialize(), <br />
how can I use them in the expression builder for Dynamic Data Fields or Dynamic Text Fields?<br />
<br />
<br />
<br />
regards
Find more posts tagged with
Comments
kclark
Hi germobirt, you can override onCreate() to be able to add text to an ITextItemInstance. You would need to create a pojo and then you can override the onCreate() from inside that. You could use some code similar to the following<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>public abstract class MyPojo extends TextItemEventAdapter implements ITextItemEventHandler {
public String getText() {
return "Some text";
}
@Override
public void onCreate(ITextItemInstance text, IReportContext reportCotnext) throws ScriptException {
super.onCreate(text, reportCotnext);
text.setText(getText());
}
}</pre>
<br />
When you say your defining global variables in initialize() are you doing this in the designer or in Java? If you're in the designer you can set the variable as a PGV like this<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportcontext.setPersistentGlobalVariable("nameofvar", "somevalue)</pre>
<br />
Then you could add this value to your dynamic text from onCreate<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>var myVar = reportcontext.getPersistentGlobalVariable("nameofvar");
this.text = myVar;</pre>