If/Else for Table sections

jballnik
edited February 11, 2022 in Analytics #1
<p>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?</p>
<p> </p>
<p>John</p>

Comments

  • Virgil Dodson
    Virgil Dodson E admin
    edited May 8, 2017 #2
    <p>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.</p>
    <p> </p>
    <p>Table 1 visibility property</p>
    <pre class="_prettyXprint _lang-">
    new Date(Date.parse(params["NewParameter"].value)).getTime() <= new Date(Date.parse(params["flipParam"].value)).getTime()
    </pre>
    <p>Table 2 visibility property</p>
    <pre class="_prettyXprint">
    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;
    }
    </pre>
    <p>I uploaded a simple example into the DevShare at <a data-ipb='nomediaparse' href='http://developer.actuate.com/community/forum/index.php?/files/file/1139-swap-table-based-on-date-parameter/'>http://developer.actuate.com/community/forum/index.php?/files/file/1139-swap-table-based-on-date-parameter/</a></p&gt;
    Warning No formatter is installed for the format ipb
  • 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:<br><br>var no_run = new String();<br><br>if(params["my_param"].value > 1000)<br><br><br>{<br>no_run = " and 1=2";<br>}<br><br><br>Then in the definition of sqlText, I do this:<br><br>sqlText = "select wonum from workorder where status = 'INPRG'";<br>+ no_run<br><br>The "and 1=2" where condition will always be false therefore returns no rows.<br><br>I hope this helps.
  • jballnik
    edited May 8, 2017 #4
    <p>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!!</p>
  • <p>You could also just drop the table in the reports beforeFactory event which prevents the query from being run as well.</p>
    <pre class="_prettyXprint _lang-">
    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();
    }
    </pre>
    Warning No formatter is installed for the format ipb