Pass current system date to a parameter of string data type in javascript

Options
system_migrated
edited February 11, 2022 in Analytics #1
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Hi,</p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">I am having a parameter of data type string and want to pass system date as a parameter value (of params["FromDate"]) in the following script,</p>
<p style="color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </p>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var oTable = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("Table1");</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">var cTable = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("Table2");</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">if(params["FromDate"].value == <span style="color:rgb(255,0,0);"><strong>"System Date</strong>"</span>)</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">{</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">cTable.drop();</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">}else {</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">oTable.drop();</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">}</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;"> </div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">Also I want one day before date of the parameter.</div>
<div style="margin:0px;color:rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;">How this can be done?</div>

Comments

  • <p>Hi,</p>
    <p> </p>
    <p>Why use a parameter of data type String? If you want to test on the date, better create a Date parameter.</p>
    <p> </p>
    <p>The following script shows both options for testing the parameter, i.e. if the date entered in the parameter is equal to the system date, or if the date entered in the parameter minus one is equal to the system date. Simply comment and uncomment the appropriate "if" statement:</p>
    <pre class="_prettyXprint _lang-">
    var oTable = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("Table1");
    var cTable = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("Table2");

    // Test for one day before the param date
    if(BirtComp.equalTo(BirtDateTime.addDay(params["FromDate"].value, -1), BirtDateTime.today()))
    // Test for entered param date
    //if(BirtComp.equalTo(params["FromDate"].value, BirtDateTime.today()))
    {
    cTable.drop();
    }else {
    oTable.drop();
    }
    </pre>
    <p>I have attached a sample report.</p>
    <p> </p>
    <p>Hope this helps,</p>
    <p> </p>
    <p>P.</p>
    Warning No formatter is installed for the format ipb
  • <p>Thanks for providing with the solution but the script is not working properly. Whatever the value of the parameter be, it is always dropping the first table. Is there a problem with the date format entered? Is there any particular format that the javascript accepts the date?</p>
    <p> </p>
    <p>Also I am passing the parameter in the query of the dataset using where clause like,</p>
    <div>WHERE</div>
    <div>"Date" BETWEEN ? AND ?</div>
    <div> </div>
    <div>Any work around for this?</div>
  • <p>Hi,</p>
    <p> </p>
    <p>Verify that your parameter is of data type Date. The script provided works only if the parameter is a date. You can take a look at the sample report I sent. By default, it should work, however the script is set to drop the bottom table when the date input in the parameter is equal to today's date minus one day (based on your original requirement)</p>
    <p> </p>
    <p>The second part to your question is a different topic altogether. If you want to filter your query between two dates, you will need two report parameters, a from date and a to date.</p>
    <p> </p>
    <p>P.</p>
    Warning No formatter is installed for the format ipb