Jump to content

BIRT Developer Center Download


Photo
* * * * * 1 votes

HTML button that calls beforeOpen() DataSet method

javascript html DataSet Parameter BIRT

  • Please log in to reply
1 reply to this topic

#1 genric

genric

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 17 May 2017 - 09:10 AM

Hi everyone,

 

Im building a report that has some textboxes filters in it. Initially the report is created without any filter. My idea is that when the user clicks on a button, the filters are applied with the Textboxes that he filled and the Query is changed to have those "wheres". The concept that i am using is the following, which was answered in another topic: 

 

Yes, you can do that. If the parameter is optional you can't use the Dataset Parameter (with a ? in your query), because it will be null. Instead you have to modify your query using JavaScript.

Create a Report Parameter like usual, in this case 'stud_no'. Then add a comment in your SQL that you are reasonably sure is unique, I use something like --$stud_no$, wherever you want your clause inserted.

Then add a script like this to your Data Set, in beforeOpen:

if (params["stud_no"].value){
this.queryText = this.queryText.replace("--$stud_no$", "and stud_no = " + params["stud_no"]);
}

This replaces the comment with the clause when the parameter has a value. You can use regex in the search string, and then you can also insert it multiple places if you want.

 

So I have two questions:

1- How can I make a Parameter receive the value of a Textbox? ;

2 - How can i make that the button calls beforeOpen() and apply the changes ?

 

Im sending what I have until now with my report, which is pretty much nothing at all because Im new with BIRT.

 

Thank you.

Attached Files



#2 jfranken

jfranken

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 18 May 2017 - 06:25 AM

Is it an absolute requirement that the user is not given the option to filter the data when the report is initially run?  The reason I am asking is because if it is okay for the user to be prompted for a parameter when they first run the report, then you can just make the parameter visible and use the built-in parameter functionality to do the filtering rather than creating a customized version.  

 

If you want the user to be able to leave the parameter blank to see the full, unfiltered data, you will need code in the beforeOpen event of the data set similar to the code you referenced.  Attached is an example based on the Classic Models database created in v 4.5.  When you run the report, you will be prompted to enter a parameter.  You can enter a parameter value to filter the data or leave it blank to see the full result set.  If you click the icon to re-run the report, you will be prompted for the parameter again.  You can change the value each time for different filtering.  Obviously you can add more parameters as needed.

 

Regards,

Jeff

Attached Files


Jeff F.

 

Customer Support Engineer I

Website: www.opentext.com

 

emailsupport-logo-opentext.gif

 

 

 






Also tagged with one or more of these keywords: javascript, html, DataSet, Parameter, BIRT