Home
Analytics
Passing Global Variable value in HTML
vishalkp
Hello All,
I want use the global variable's value in script written in the text(HTML) Format.
I tried using reportContext.getPersistentGlobalVariable("b1");
but it is not working.
Do reply your suggestion...
Thanks in Advance...
With Regards,
VishalKP.
Find more posts tagged with
Comments
bhanley
You will need to assign the value in the Global Variable to a report parameter. You can create a hidden, non-required parameter that will not interfere with the user's experience. Assign the value to a parameter in a scripting event. At that point the expression builder used by the Text control has access to the report parameters via the "<em class='bbc'>VALUE OF</em>" construct.
vishalkp
Thanks Bhanley for your quick response and your valuable suggestion,
The option you suggested is right.
I had used the same method and had taken
"<value-of>reportContext.getPersistentGlobalVariable("b"+i)</value-of>".
Let me explain bit more.
i am assigning values to the global variables which are created as (b+incrementing number) i.e (b1,b2,b3...)
Now i am using FOR LOOP in javascript of HTML as:
for (i=1;i<=cnt;i++)
{
alert("b"+i);
str = "BU_<value-of>reportContext.getPersistentGlobalVariable("b"+1)</value-of>";
alert(str);
str1 = "BU_<value-of>reportContext.getPersistentGlobalVariable("b"+i)</value-of>";
alert(str1);
}
In the 1st alert i get value b1
2nd alert i get value BU_workshop
but in the 3rd alert i get the value as BU_(blank).
i tried using parameter but the it aslo shows blank value as i have not assinged default values to the parameter, as it will come from database.
so can you please help me out to sovle this problem bu suggesting how to use global variable in
str1 = "BU_<value-of>reportContext.getPersistentGlobalVariable("b"+i)</value-of>";
Thanks in Advance,
With Regards,
VishalKP.
bhanley
Sounds like something odd is happening when the variable is interpreted. Can you try explicitly sending the "i" variable to a String?<br />
<br />
Like this:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
for (i=1; i<=cnt; i++){
alert("b" + i);
str = "BU_<value-of>reportContext.getPersistentGlobalVariable("b" + 1) </value-of>";
alert(str);
str1 = "BU_<value-of>reportContext.getPersistentGlobalVariable("b" + i.toString())</value-of>";
alert(str1);
}</pre>
vishalkp
Hello Bhanley,
Thanks again.
But i had tried this also and tried again as you suggested.
str1 = "BU_<value-of>reportContext.getPersistentGlobalVariable("b" + i.toString())</value-of>";
alert(str1);
But Still it shows blank value as "BU_(blank)"
please suggest any other option.
Thanks In Advance...
With Regards,
VishalKP.
vishalkp
Hello Bhanley,
Yet I am not able to get the value of persistent global variable in the loop, as we discussed earlier.
I also tried using concating the string and got the alert as required (i.e reportContext.getPersistentGlobalVariable("b1")),
but finally when i have to use the String in "<value-of>final_string_appended</value-of>", then there is error saying that "final_string_appended" is not defined.
Is there any way to contact you or your team by means of telephonic call ?
Please reply your suggestions...
Thanks in Advance...
With Regards,
VishalKP.
bhanley
I do not understand where you are currently. It sounds like you got the concatenation to work, but now you are having trouble using the result? Can you post the script that is <em class='bbc'>almost </em>working so I can have a look?<br />
<br />
<strong class='bbc'><em class='bbc'><value-of>final_string_appended</value-of></em></strong> is not working because <em class='bbc'>final_string_appended</em> is not a meaningful name to something in the BIRT scripting layer. If I can see the script as you have it currently we should be able to put the last pieces in place.
vishalkp
Hello Bhanley,<br />
<br />
Thanks for response.<br />
<br />
I got the solution and it works fine.<br />
<br />
I used a global arraylist to get the dataset values to be filled in it.<br />
And then in the script i wrote as:<br />
var i = 0;<br />
var cnt = <value-of>reportContext.getPersistentGlobalVariable("Count")</value-of>; ---count of rows<br />
alert(cnt);<br />
<br />
var str = "";<br />
var bu = new Array(cnt); --- new array with size of count<br />
var str1 = "";<br />
var str2 = "";<br />
var str3 = "";<br />
var str4 = "";<br />
var str5 = "";<br />
<br />
str="<value-of>reportContext.getPersistentGlobalVariable("MyArrayList")</value-of>"; ---MyArrayList --> global array.<br />
<br />
bu=str.split(","); --> to split ","<br />
<br />
for (i=0;i<=bu.length;i++)<br />
{<br />
"BU"+bu
;<br />
}<br />
<br />
Thanks for your valuable time...<br />
<br />
With Regards,<br />
VishalKP.