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)
Global js function used by dataset parameter seems not working
Stefan734
<p>Hi experts,</p>
<p>I've created some birt reports, but I'm far away from expert status. Hope anyone here can help me to solve this "basic task"...</p>
<p> </p>
<p>I want to use a global js function or global js variable to set a dataset parameter. Therefore I've created an external js file and linked it with my report. Alternatively, I added this function in the initialize event of report and don't use the external file</p>
<pre class="_prettyXprint">
// Example external js function
function myString( str )
{
return str + 'globaltest';
}
</pre>
<p>When using myString ( 'test' ) as a default value expression for dataset parameter I got always following error message: "myString" is not defined.</p>
<p> </p>
<p>I've checked it with an report parameter instead of the default expression but the behavior is similar.</p>
<p>In addition I added reportContext.setPersistentGlobalVariable( "myString", myString) and would like to get the information by reportContext.GetPersistentGlobalVariable( "myString") but report parameters and dataset parameters seems no reportContext or can't use global js functions/variables.</p>
<p> </p>
<p>I've no more idea but I'm sure some basic is missing :unsure: I'm on birt 2.5.1</p>
<p>Thanks in advance</p>
Find more posts tagged with
Comments
JFreeman
<p>How are you wanting to use this global variable and dataset parameter?</p>
<p>Are you trying to modify the database query?</p>
<p>Use it to set a filter on the data set?</p>
Matthew L.
<p>The function works for me in 2.5.1, when adding it to the initialize method (See example).</p>
<p>I wonder if it could be the order of operations which are causing the error.</p>
<p>Could you post an example that replicates the issue?</p>
Stefan734
<p>It should be a parameter for queries and more, therefore a global Variable and the use of dataset parameters</p>
<pre class="_prettyXprint _lang-sql">
select FIELD_1, FIELD_2 from VIEW_1
where LOGIN_ID = ?
</pre>
JFreeman
<p>Take a look at the sample report upload by Matthew.</p>
<p> </p>
<p>It successfully uses your function in initialize of the report design with a parameter in the data set.</p>
Stefan734
<p>Hi Matthew,</p>
<p>thanks for your example...</p>
<p>I added a report parameter and your example shows the same error message 'myString is not defined'</p>
<p> </p>
<p>edit<br>
Attachment not attached
</p>
Matthew L.
<p>Without an example its hard to tell exactly how you are setting up the report design that causes this issue.</p>
<p>However, if you are attempting to call a function from a reports initialize method in a Report Parameter's value then this will not work.</p>
<p>Per the order of operations, the parameter's run before the report's initialize method which is why you see the undefined error.</p>
<p> </p>
<p>Depending on what you are wanting to do, you could use the value from your parameter as the input parameter to the function for your Data Set input parameter.</p>
<p> </p>
<p>ex: myString(params["NewParameter"]);</p>
<p> </p>
<p>Edit:</p>
<p>Per your newly attached example, I do not see where you are actually using parameter value however hopefully this attached example is helpful.</p>
Stefan734
<p>OK, let explain the use case but be aware that English is not my core competence
</p>
<p> </p>
<p>Szenario</p>
<p>First the report user should be able to choose one or more for him possible record classes (field based information in database).</p>
<p>After selection the report shows all detailed informations for the selected groups from other sql join dataset.</p>
<p> </p>
<p>The first sql for the dynamic report parameter depence on userID from report user in the where clause.</p>
<p>The second sgl use the selected values from report parameter as IN clause.</p>
<p> </p>
<p>Because userID is used more times I think a global variable instead of report paramter is a good idea. But "parameter's run before the report's initialize method" is the end for my idea
.</p>
Matthew L.
<p>I think the solution you are looking for is is similar to another issue <a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/topic/36152-filters-not-adequate-for-large-data-what-then/?p=133966'>http://developer.actuate.com/community/forum/index.php?/topic/36152-filters-not-adequate-for-large-data-what-then/?p=133966</a></p>
;
<p> </p>
<p>Attached is an example that passes multiple values selected from a parameter into the query.</p>
<p>I have 1 for an Integer type and one for String type depending on the values you are passing.</p>
<p> </p>
Stefan734
<p>Passing multiple values to a sql isn't a problem for me.</p>
<p> </p>
<p>First I need a dynamic report parameter with a subset of records based on current report user ID. I can get it in two ways (2. for testing in designer)</p>
<p> </p>
<p>1. reportContext.getHttpServletRequest().getSession().getAttribute( "AppContextValue" ).get( "user" )</p>
<p>2. reportContext.getDesignHandle().findDataSource( "****" ).getProperty( "user" )</p>
<p> </p>
<p>The challange seems that 'initialize event' fires after report parameter and for report parameters I've no access to this objects/information.</p>
<p> </p>
Matthew L.
<p>Try the following in the parameter's Expression Builder:</p>
<pre class="_prettyXprint _lang-js">
this['user.name'];
</pre>
Stefan734
<p>Thanks for your well support. Unfortunately I had no system access today, I will try it tomorrow...</p>
Stefan734
<p>We use Birt in conjunction with our main application BMC Remedy. In this context this shows the system user and not the current birt user. I can't use it...</p>
<p> </p>
<p>However, you solve my problem. I've to add the code in parameter expression and can't use global variables was the important hint.</p>
<p> </p>
<p>Thanks again.</p>