Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Wiki Markup
{scrollbar}

This action executes the specified Javascript. Parameters specified as inputs will be available to the script for use. The JavascriptRule can have one or more outputs.
The component can also define library elements in the component definition. Each specified library file must exist in the solution, and will be pre-pended to the script that's specified in the component definition. In this way, you can create a library of commonly used javascript code, and include it at runtime execution.

...

Code Block
javascript
javascript
titleThe following functions are available from JavaScriptSome JavaScript examples for working with result sets

getColumnCount()                   // Number of columns
getRowCount()                      // Number of rows
getValueAt( row, col )             // Returns the value os a cell, row and column are zero based
setColumnHeaders( array )          // array size should match the number of columns
setColumnHeaders( array1, array2 ) // array1 for col headers, array2 for column types
addRow( array )                    // array is a data row to add to the end of the result set
getMetaData()                      // Returns a IPentahoMetaData object


// Example: Create a result set

var results = new JavaScriptResultSet();
results.setColumnHeaders( 'DIAL_DATA', 'DIAL_MIN', 'DIAL_MAX' );
results.addRow( new Array(57.0, 0.0, 100.0) );

// Example: Create a result and access it's data

var results = new JavaScriptResultSet();
results.setColumnHeaders( 'REGION' );
results.addRow( new Array( 'Eastern' ) );
results.addRow( new Array( 'Western' ) );
results.addRow( new Array( 'Southern' ) );

firstrow = results.getValueAt(0,0);                      // returns '[Eastern]'
lastrow = results.getValueAt(results.getRowCount()-1,0); // returns '[Southern]'
columns = results.getColumnCount();                      // returns 1
rows = results.getRowCount();                            // returns 3


// Other useful methods 

var meta = result_set.getMetaData();      // Returns an IPentahoMetaData object
var colCount = meta.getColumnCount();
var colHeaders = meta.getColumnHeaders(); //getColumnHeaders() returns object[][]

var i = 0;
for ( i = 0 ; i < colCount ; i++ ){
    colName=colHeaders[0][i];
     // use colName for something
}