Go Back   Forum - BIRT Exchange > Designing BIRT Reports Forums > Designing BIRT Reports

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-30-2009, 01:57 PM
Junior Member
 
Join Date: Jun 2009
Posts: 2
Default Storing query result in report parameter

Hi,

I need to get a value using SQL and use this value later in the report as parameter for other queries and various conditions.

For example, I need to call this query somewhere in the early stages of report (initialize, before factory, etc):

select userid from users where ....

and then store this "userid" as parameter for later use.

Any advice?

I am using 2.3.2

Thank you
Reply With Quote
  #2 (permalink)  
Old 06-30-2009, 02:47 PM
Senior Member
 
Join Date: Oct 2007
Posts: 462
Default

Once you have your UserID, you can set a persistent global variable in the scripting layer. This variable will be available within any other event handler you may need:

Code:
reportContext.setPersistentGlobalVariable(name, value);
You can also directly set the value of the report parameter in a script. this will allow you to bind the value into a query using the data set editor (take care when you do this assignment as your Data Set may have already been built:

Code:
params["param_name"].value = "something";
A last option would be to modify your query in the Data Set's initialize script. There you can check your persistent global variable and use the value to further tweak your query text.

Code:
this.queryText = this.queryText + " WHERE userid = " + reportContext.getPersistentGlobalVariable("userID");
Any of those approaches should work fine.

Good Luck!!
__________________
--Brian
http://www.twitter.com/brianhanley
Reply With Quote
  #3 (permalink)  
Old 07-01-2009, 09:49 AM
Junior Member
 
Join Date: Jun 2009
Posts: 2
Default

Thanks a lot!

How can I ensure that the SQL that returns my userIdValue is executed before any other queries that are used in the report?

Say, I want to run the query first (getting userIdValue), then then do as you advised.

Code:
reportContext.setPersistentGlobalVariable(name, userIdValue);
Is there any call to execute the SQL from javascrip?

Thanks!
Reply With Quote
  #4 (permalink)  
Old 07-01-2009, 12:02 PM
Senior Member
 
Join Date: Oct 2007
Posts: 462
Default

You should probably create a Java Event Handler and invoke that via the report's initialize event. Executing SQL from a full-blown Java object will perform much better.

There are examples for creating these handlers on the DevShare.

Using Java to Write a BIRT Event Handler - Tips & Tricks - BIRT Exchange

Good Luck!
__________________
--Brian
http://www.twitter.com/brianhanley
Reply With Quote
Reply


Thread Tools
Display Modes




All times are GMT -7. The time now is 06:00 AM.
Powered by vBulletin Copyright © 2000-2010 Jelsoft Enterprises Limited.


Content Relevant URLs by vBSEO 3.1.0