Search code examples
mdxpentaho-cde

Set default value for the select component in pentaho CDE


I have 1 combobox in layout, 1 select component and 1 datasource (mdx over mondrianJndi)

Here my mdx query

with member [Measures].[Name] as '[Year].CurrentMember.UniqueName' select TopCount( filter({Descendants([Year].[All Years] ,[Year].[Year])}, not isempty(([Year].CurrentMember)) ) , 50) on ROWS, 
 {[Measures].[Name]} on Columns 
 from [Department Cube]

My query return a list of year have data (include current year)

At this time, I have to wait data loaded then set the value of combobox to the current year by js resource. How can I set default value is current year to the combobox in layout with out wait the data loaded ?


Solution

  • Being a dynamic query you shouldn't rely on "current" year calculations. Any JS function to determine the current year, e.g. from the client's clock will suffer from timezone oddities and may try to set the value to something that isn't returned from the query.

    You should set the default of the selector only after reading the query results, but the best place to do so is in the postFetch method of the component.

    For example, if you want to set the parameter value to be the last value of the query results,

    function(data){
      var results = data.resultset
      // some logic here to set current_year to the adequate value. For example,
      current_year = results[results.length-1][0];
      dashboard.setParameter(this.parameter, current_year);
      return data;
    }