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)
how and where to create global variable
JavaNep
Hi BIRT gurus,
I am super new to BIRT. How and where should i declare global Variable. and how to retrive it to incluse it in report parameter.
if u can provide step by step instruction that would be really helpful .
thanks in advance
Find more posts tagged with
Comments
kclark
You can declare a persistent global variable in your script using<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportContext.setPersistentGlobalVariable(data,variablename);</pre>
<br />
As an example create a new parameter. Check hidden and uncheck required. Then add this code to the initialize() of your report.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportContext.setPersistentGlobalVariable("test","myvar");
params["NewParameter"] = reportContext.getPersistentGlobalVariable("test");</pre>
<br />
The first line will assign the value "myvar" to the persistent global variable "test" while the second line assigns that value to the parameter. If you want to make sure this has been assigned then drag a dynamic text object to your report and add this to the expression builder and run the report.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>params["NewParameter"].value</pre>
<br />
You should see "myvar" on the report.
JavaNep
Thank you for ur reply Clark. What I am trying to achieve is I want to to declare local variable which changes everytime I click the parameter value of lets say first param p_country and second param p_city of cascaded parameter. <br />
First i want to select the country from p_city and according to that value i wan to be able to get the static value (hard coded city value) in the second param p_city , for which i thought I could be able to do using global variable . <br />
i tried using ur method in initialise <br />
and called it in getDefaultValueList script but it shows null when i debugged .<br />
any suggestion <br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="113320" data-time="1358358898" data-date="16 January 2013 - 10:54 AM"><p>
You can declare a persistent global variable in your script using<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportContext.setPersistentGlobalVariable(data,variablename);</pre>
<br />
As an example create a new parameter. Check hidden and uncheck required. Then add this code to the initialize() of your report.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportContext.setPersistentGlobalVariable("test","myvar");
params["NewParameter"] = reportContext.getPersistentGlobalVariable("test");</pre>
<br />
The first line will assign the value "myvar" to the persistent global variable "test" while the second line assigns that value to the parameter. If you want to make sure this has been assigned then drag a dynamic text object to your report and add this to the expression builder and run the report.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>params["NewParameter"].value</pre>
<br />
You should see "myvar" on the report.<br /></p></blockquote>
kclark
The parameters page is called before everything else and nothing is set until you click the ok button. I think the best way to get the results you want is to create two reports. The first one will be like a landing page, where you get the state. Then the first report will pass the state to the second (real) report and you can set the parameter statically based on the value that was passed to it in getDefaultValueList() with an if/then statement.
JavaNep
thanks for the reply . any examples i cd get wd clarify me .. <br />
<br />
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="113328" data-time="1358374358" data-date="16 January 2013 - 03:12 PM"><p>
The parameters page is called before everything else and nothing is set until you click the ok button. I think the best way to get the results you want is to create two reports. The first one will be like a landing page, where you get the state. Then the first report will pass the state to the second (real) report and you can set the parameter statically based on the value that was passed to it in getDefaultValueList() with an if/then statement.<br /></p></blockquote>
JavaNep
Any help please
Hans_vd
Is this the same question as
http://www.birt-exchange.org/org/forum/index.php/topic/28639-cascade-parameter-help/page__gopid__113356&#entry113356
?
JavaNep
yes it is regarding same issue.. I have replied on ur post on that, as i still have some issue understanding ur answer . <br />
<blockquote class='ipsBlockquote' data-author="'Hans_vd'" data-cid="113358" data-time="1358437727" data-date="17 January 2013 - 08:48 AM"><p>
Is this the same question as <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/28639-cascade-parameter-help/page__gopid__113356&#entry113356'>http://www.birt-exchange.org/org/forum/index.php/topic/28639-cascade-parameter-help/page__gopid__113356&#entry113356</a>
; ?<br /></p></blockquote>
zsh
<p>Report parameters are visible for at the html source of a report running. To avoid observing parameters and variables I try to hardcode them. However, it is inconvenient to maintain several variables in various scripts. And also, these variables should be loaded before parameter page because parameters are linked to that values.</p>
<p> </p>
<p>Referring to the previous comment:</p>
<p><em>"The parameters page is called before everything else and nothing is set until you click the ok button. I think the best way to get the results you want is to create two reports. The first one will be like a landing page, where you get the state. Then the first report will pass the state to the second (real) report and you can set the parameter statically based on the value that was passed to it in getDefaultValueList() with an if/then statement."</em></p>
<p> </p>
<p>Threfore, I am trying to implement a master report that declares variables and passes them to subreports.</p>
<p> </p>
<p>What scripts should contain "global" variables?</p>
<p>How to declare these variables in master report?</p>
<p>How to reference to these variables from subreports?</p>
<p> </p>