Previous Next

Task 3:  Conditionally increment the counter

To count the number of customers with the string Mini in their names, examine each customer’s name and add one to the counter for every occurrence. A logical place to perform this task is in the Row.onCreate method, which executes for every retrieval of a row of data from the data source.


Figure 23-8 onCreate( ) in the Script window

Figure 23-8  onCreate( ) in the script window
myrow=this.getRowData( );
Notice that when you enter the period after this, a pop-up containing all the available methods and properties, including getRowData appears. This line of code gets an instance of IRowData, which has a method, getExpressionValue( ), to get the contents of a column of the row.
CustName=myrow.getExpressionValue( "row[CUSTOMERNAME]" );
This line of code returns the contents of the table column that comes from the CUSTOMERNAME column in the data set.
if( CustName.indexOf( "Mini" ) != -1 ) countOfMinis += 1;
You can use the JavaScript palette to insert each of the following elements in the preceding line:
Select Native ( JavaScript ) FunctionsString FunctionsindexOf( )
Select OperatorsComparison!=
Select OperatorsAssignment+=

(c) Copyright Actuate Corporation 2012