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.

1  
2  

Figure 23-8 onCreate( ) in the Script window

Figure 23-8  onCreate( ) in the script window
3  
row=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.
4  
CustName=row.getExpressionValue( "row[CUSTOMERNAME]" );
This line of code returns the contents of the table column that comes from the CUSTOMERNAME column in the data set.
5  
if( CustName.indexOf( "Mini" ) != -1 ) countOfMinis += 1;
You can use the JavaScript palette to insert each of the following elements in the preceding line:
n  
Select Native ( JavaScript ) ObjectsString FunctionsindexOf( )
n  
Select OperatorsComparison!=
n  
Select OperatorsAssignment+=
6  

(c) Copyright Actuate Corporation 2011