Search code examples
pentahopentaho-cdepentaho-ctools

how to set current month as default value on simple parameter on pentaho cde?


I have a simple parameter where I should pass the first day of current month. What should I write on property value?

enter image description here


Solution

  • You can create a custom parameter, which allows you to set it to the return value of a Javascript function:

    function(){
      var now = new Date();
      return now.getMonth() + 1;
    }
    

    When you load the dashboard the parameter will be calculated and will have an integer value between 1 and 12.

    If you want the parameter to have as value the date string for day 1 of this month you can instead use

    function(){
      var now = new Date();
      var y = now.getFullYear();
      var m = now.getMonth()+1;
      m = (m<10 ? '0' : '') + m;
      var d = '01';
      return y + '-' + m + '-' + d;
    }
    

    This will return the date as a string in the format yyyy-MM-dd for day 1 of the current month.