Jump to content

BIRT Developer Center Download


Photo
- - - - -

If/Else for Table sections


  • Please log in to reply
4 replies to this topic

#1 jballnik

jballnik

    Junior Member

  • Members
  • PipPipPip
  • 70 posts

Posted 07 May 2017 - 10:29 AM

Hey Gang, we have a request to not run the report if a particular date parameter is below a certain date. Is there a way to handle IF/ELSEs for tables? So if the date parameter is below a certain date run and display this table section, if it's above run and display another table section. Make sense?

 

John



#2 Virgil

Virgil

    Administrator

  • Administrators
  • 1052 posts

Posted 08 May 2017 - 10:09 AM

Hi John, you can create 2 different tables and then check your date parameter in the visibility property to determine if you should display it or not.  I think date and time checking is a little tricky to get working the first time but the below scripts work for me when set on the visibility property of the tables.  In the examples below. I did it two different ways but in both, the user passes in a date as NewParameter and compares it against flipParam which a hidden parameter set by you.

 

Table 1 visibility property

new Date(Date.parse(params["NewParameter"].value)).getTime() <= new Date(Date.parse(params["flipParam"].value)).getTime()

Table 2 visibility property

var paramDate = new Date(Date.parse(params["NewParameter"].value));
var flipDate = new Date(Date.parse(params["flipParam"].value));

var paramDateComp = paramDate.getTime();
var flipDateComp = flipDate.getTime();

if (paramDateComp > flipDateComp) {
  true;
} else {
  false;
}

I uploaded a simple example into the DevShare at http://developer.act...date-parameter/


Virgil Dodson 
BIRT Evangelism | OpenText Analytics and Reporting
http://developer.actuate.com


#3 rdpeterson

rdpeterson

    Advanced Member

  • Members
  • PipPipPip
  • 48 posts

Posted 08 May 2017 - 10:24 AM

Is each table associated with its own data set? I sometimes have a single query associated with multiple tables and set the visibility of each table based on the value of one or more parameters, or on the results of another data set associated with another table before the subject table. I also have reports with dedicated data set per table and I only display one table based on parameter values. Again, I control visibility of the tables based on the parameter values. If the data sets (queries) are complex and take a significant time to run, I will also alter the query(s) that I don't want to run by modifying the code based parameter value. Very often my code to modify the SQL string will look something like this:

var no_run = new String();

if(params["my_param"].value > 1000)


{
no_run = " and 1=2";
}


Then in the definition of sqlText, I do this:

sqlText = "select wonum from workorder where status = 'INPRG'";
+ no_run

The "and 1=2" where condition will always be false therefore returns no rows.

I hope this helps.

#4 jballnik

jballnik

    Junior Member

  • Members
  • PipPipPip
  • 70 posts

Posted 08 May 2017 - 02:14 PM

Thanks Guys, I modified the SQL statement and depending on what was entered as the parameter I tack on 1=2 or 1=1. Works like a charm. Thanks gang!!



#5 Virgil

Virgil

    Administrator

  • Administrators
  • 1052 posts

Posted 09 May 2017 - 08:44 AM

You could also just drop the table in the reports beforeFactory event which prevents the query from being run as well.

var paramDate = new Date(Date.parse(params["NewParameter"].value));
var flipDate = new Date(Date.parse(params["flipParam"].value));

var paramDateComp = paramDate.getTime();
var flipDateComp = flipDate.getTime();

if (paramDateComp > flipDateComp){
  //don't forget to name your tables in the property editor
  reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("table1").drop();
} else {
  reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("table2").drop();
}

Virgil Dodson 
BIRT Evangelism | OpenText Analytics and Reporting
http://developer.actuate.com