Skip to main content
Pentaho Documentation

APIs for Report

Overview

Details methods for api.report class.

api.report Class

Report definition for api class. Contains all report related API calls.

Methods

The following methods are applicable:

addLayoutField (gembarId formula gembarOrdinal)

Adds a single gem to the gembar via its formula. The gembarOrdinal allows one to set the location of of the inserted gem.

Parameters:

  • gembarId (String)

    This is the id of the gembar. It depends on the visualization's type. For example, PIVOT allows values such as "rows", "columns", "measures".

  • formula (String)

    This is the String representation of the formula to insert as a gem.

  • gembarOrdinal (Number)

    This is the index at which to insert the gem. A value of -1 appends to the end of the list.

Example:

var gembarId = "rows";
var formula = "[Markets].[City]";
var gembarOrdinal = 1;
api.report.addLayoutField( gembarId, formula, gembarOrdinal );

getFieldOption (formula name) String

Returns the field option's value by name for a given formula. For additional information, see APIs for Get/Set Field Options.

Parameters:

  • formula (String)

    This is the string representation of the formula.

  • name (String)

    This is the name of field's option.

Returns:

  • String

    This is the option's value.

Example:

api.report.getFieldOption("[Markets].[Territory]", "showSubtotal");

getFilters ()

Returns all non-numeric filters on the report. For additional information, see Analyzer Filters.

Returns:

  • JSON filters

         This is a JSON object containing all non-numeric filters.

Example:

 api.report.getFilters();

 Return Value:

{"filters": {"[Time].[Years]": [
 {"operator": "EQUAL", "members": [
 {"formula": "[Time].[2003]", "caption": "2003"},
 {"formula": "[Time].[2004]", "caption": "2004"},
 {"formula": "[Time].[2005]", "caption": "2005"}
   ]}
 ]}}

getLayoutFields (gembarId) Array

Returns the array of formulas for the layout fields by gembarId.

Parameters:

  • gembarId (String)

    This is the id of the field. It depends on the visualization's type. For example, PIVOT allows values such as "rows", "columns", "measures".

Returns:

  • Array

    This is the array of formulas.

Example:

var gembarId = "rows";
api.report.getLayoutFields(gembarId);

Return Value:
["[Markets].[Territory]"]

getName () String

Returns the name of the current report. New reports will return a null value.

Returns:

  • Name of the current report.

Example:

api.report.getName();

Return Value:
"Country Performance (heat grid)"

getNumericFilters ()

Gets the numeric filters for the report. Note that a report may only have a single level with a numeric filter and that level must be displayed on the report. For additional information, see Analyzer Filters.

Returns:

  • All filters in a JSON object.

Example:

api.report.getNumericFilters();

 Return Value:
{"filters": {"[Markets].[Territory]": [
{"count": "10", "formula": "[Measures].[Sales]", "operator": "TOP"},
{"operator": "GREATER_THAN", "formula": "[Measures].[Sales]", "op1": "0.0"},
{"operator": "LESS_THAN", "formula": "[Measures].[Sales]", "op1": "100000000000"},
{"operator": "IS_NOT_EMPTY", "formula": "[Measures].[Sales]"}
]}}

getPath () String

Returns the path of the current saved report. New reports will return a null value.

Returns:

The report's path.

Example:

api.report.getPath();

Return Value:
"/public/Steel Wheels/Country Performance (heat grid).xanalyzer"

getVizId () String

Returns the current visualization id.

Returns:

The id of the visualization.

Example:

api.report.getVizId();

Return Value:
"ccc_bar"

removeFilters (level)

Removes all non-numeric filters for a given level.

Parameters:

  • level (Object)

    This is the level on which the filter is being removed.

Example:

api.report.removeFilters("[Markets].[Territory]");

removeLayoutField (gembarId formula)

Removes a single gem from the gembar utilizing its formula as the key.

Parameters:

  • gembarId (String)

    This is the id of the field. It depends on the visualization's type. For example, PIVOT allows values such as "rows", "columns", "measures".

  • formula (String)

    This is the string representation of the formula to insert as a gem.

Example:

var gembarId = "rows";
var formula = "[Markets].[City]";
api.report.removeLayoutField(gembarId, formula);

removeNumericFilters ()

Removes all numeric filters on the report.

Example:

api.report.removeNumericFilters();

setFieldOption (formula name value)

Sets the field option's value by name for a given formula. For additional information, see APIs for Get/Set Field Options.

Parameters:

  • formula (String)

    This is the string representation of the formula.

  • name (String)

    This is the name of the field's option.

  • value (String)

    This is the value of the field's option.

Example:

api.report.setFieldOption("[Markets].[Territory]", "label", "My Territory");

setFilters (level filterItems)

Sets non-numeric filters on a level removing all previous non-numeric filters. For additional information, see Analyzer Filters.

Parameters:

  • level (Object)

    This is the level on which the filter is being set.

  • filterItems (Object)

    The JSON representation of the filter items. Supported Operators: EQUAL, NOT_EQUAL, CONTAIN, NOT_CONTAIN, BEFORE, AFTER, BETWEEN, TIME_AGO, TIME_AHEAD, TIME_YAGO, TIME_RANGE_PREV, TIME_RANGE_NEXT

Example:

api.report.setFilters("[Time].[Years]" , [
{ // Builds a relative equal filter for Previous, Current, and Next on Years
 "operator": "EQUAL",
 "members": [-1, 0, 1]
},
{ // Builds an exact equal filter on Years
  "operator": "EQUAL",
  "members": [
  { "formula": "[Time].[2003]", "caption": "2003" }, 
  { "formula": "[Time].[2004]", "caption": "2004" }, 
  { "formula": "[Time].[2005]", "caption": "2005" }]
}, {
  "operator": "TIME_RANGE_PREV",
  "members": [10]
}, {
  "operator": "TIME_RANGE_NEXT",
  "members": [10]
}, {
  "operator": "TIME_AGO",
  "members": [10]
}, {
  "operator": "TIME_AHEAD",
  "members": [10]
}, {
  "operator": "BETWEEN",
  "members": [
    {"formula": "[Time].[2003]", "caption": "2003"},
    {"formula": "[Time].[2005]","caption": "2005"}]
}]);


api.report.setFilters("[Markets].[Territory]" , [{
  "operator": "CONTAIN",
  "members": ["APAC"]
}]);

setLayoutFields (gembarId formulas)

Sets the array of formulas for the layout fields by gembarId. It overwrites the existing fields in the current gembar. Each formula is validated. If the formula is invalid, then it will not be set.

Parameters:

  • gembarId (String)

    This is the id of the gembar. It depends on the visualization's type. For example, PIVOT allows values such as "rows", "columns", "measures".

  • formulas (Array)

    This is the array of strings of formulas.

Example:

var gembarId = "rows";
var formulas = [ "[Markets].[Territory]", "[Markets].[Country]" ];
api.report.setLayoutFields(gembarId, formulas);

setNumericFilters (level filter)

Sets a numeric filter on a level. There can only be one numeric filter per report. This method will remove any pre-existing numeric filter on the report. For additional information, see Analyzer Filters.

Parameters:

  • level (Object)

    This is the level on which the filter is being set.

  • filter (Object)

    A JSON filter representation. Supported Operators: LESS_THAN, GREATER_THAN, LESS_THAN_EQUAL, GREATER_THAN_EQUAL, EQUAL, NOT_EQUAL, BETWEEN, IS_NOT_EMPTY, TOP, BOTTOM, TOP_BOTTOM

Example:

api.report.setNumericFilters("[Markets].[Territory]", [{"count": "10", "formula": "[Measures].[Sales]", "operator": "TOP"}, {"operator": "GREATER_THAN", "formula": "[Measures].[Sales]", "op1": "0.0"}, {"operator": "LESS_THAN", "formula": "[Measures].[Sales]", "op1": "100000000000"}, {"operator": "IS_NOT_EMPTY", "formula": "[Measures].[Sales]"}]);



setVizId (vizId)

Sets the report visualization using the visualization id.

Parameters:

  • vizId (String)

    This is the id of the visualization.

Example:

api.report.setVizId("ccc_bar");