Hitachi Vantara Pentaho Community Forums
Results 1 to 6 of 6

Thread: Passing Parameters to expressions

  1. #1
    Join Date
    May 2012
    Posts
    12

    Default Passing Parameters to expressions

    Can I pass dynamic parameters to BSF/BSH?

    I want to have details header as dates of a month, like 03/11 03/12 03/13 03/14 and so on

    I have written BSF expression as:-
    Code:
    Calendar cal = Calendar.getInstance();
    cal.setTime((java.util.Date) dataRow.get("date_from"));
    cal.add(Calendar.DAY_OF_MONTH, 1);
    return cal.getTime();
    Here I'm adding one day, can I pass the number of days to be added to the expression?

  2. #2
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    To be honest, you dont even need scripting for that. Just use a ordinary date-field with the format string of "MM/yy" in the header to print your "date_from" field.

    The only way to pass parameter in is via the "date_from". A expression consumes either parameter or values from the data-row. As you already know, values from the data-row are accessed via "dataRow.get("name")". Expression parameter are static design-time values specified by the designer of the report. For scripts, we see no need for them, as you can change the script to change parameter values. If you want it to have it easier to maintain your script in the future, you can use standard programming techniques like putting all parameter into variables that are declared at the beginning of the file, etc.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  3. #3
    Join Date
    May 2012
    Posts
    12

    Default

    But then I have only one parameter, which is "date_from" which is the starting date, and other dates are generated by adding days to the "date_from" parameter. How do I add days without using scripts?

  4. #4
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    You could use a formula instead. Much easier to read.

    =DATEVALUE([date_from] + 1)

    adds one day to your date.

    You would still have to have multiple instances of that formula in your report, one for each distinct number of dates you want to add.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  5. #5
    Join Date
    May 2012
    Posts
    12

    Default

    That helps, but, wouldn't it be good if we have formulas in which parameters could be passed form within the reports?

    Thanks.

  6. #6
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    A parameter is a design-time static value. So in any case, you will have to declare n functions if you want to have n distinct parameter values.

    You could make a good and sensible case for a feature request for "Create a function library so that code does not get copied/pasted all over the report and that such complex calculations can be easily parametrized". Call it "Stored-procedures" for report scripts and formulas

    Wh not create a JIRA case for it @ http://jira.pentaho.com/browse/PRD
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.