Creating a custom web page using the Actuate JavaScript API : Viewing a report as a data service : Using a result set component

Using a result set component

The actuate.data.ResultSet class is the container for the report data obtained with actuate.dataservice.downloadResultSet( ). Because a ResultSet object is not a display element, an application can process or display the data in an arbitrary fashion.

The ResultSet class organizes report data into columns and rows, and maintains an internal address for the current row. To increment through the rows, use the ResultSet’s next( ) function as shown in the following code:

function displayData(rs)
{
  while (rs.next( ))

In this example, rs is the ResultSet object passed to the displayData callback function. To read the contents of the ResultSet object, a while loop increments through the rows of data with rs.next( ).

To get the values from a row in a ResultSet, use the getValue( ) function. The getValue( ) function takes a column name or index as an input parameter to identify the specific cell in the current row to access. To obtain the column names, use the getColumnNames( ) function. Combine the two to get the contents of a specific cell, as shown in the following code:

var columns = rs.getColumnNames( );
for (var i = 0; i < columns.length; i++)
{
  document.writeln(rs.getValue(columns[i]));
}

In this example, getColumnNames( ) returns an array of strings for the column names and puts that array into the columns variable. The for loop iterates for each value in the column array. At each iteration, the function writes a new line with the value of the cell from the current row to the current document as a new line, displaying a list of the row’s values on the page.

The following example code prints all of the ResultSet’s contents to a page, one cell’s contents per line:

function displayData(rs){
  var columns = rs.getColumnNames( );
  while (rs.next( )){
    for (var i = 0; i < columns.length; i++){
      document.writeln(rs.getValue(columns[i]));
    }
  }
}

(c) Copyright Actuate Corporation 2011