> ### 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 | In Layout, select the Row. Then, choose Script.

> 2 | From the list of available scripts at the top of the script window, select onCreate, as shown in Figure 22-8.

> Figure 22-8 onCreate( ) in the script window

> 3 | Type the following line of JavaScript code 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.

> 4 | Type the following line of JavaScript below the line you typed in step 3:

> 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.

> 5 | Type the following line of code to increment conditionally the counter you created in Task 2.

> if( CustName.indexOf( "Mini" ) != -1 ) countOfMinis += 1;
> You can use the JavaScript palette to insert each of the following elements in the preceding line:

> | indexOf( )

> Select Native ( JavaScript ) Functions→String Functions→indexOf( )

> | !=

> Select Operators→Comparison→!=

> | +=

> Select Operators→Assignment→+=

> 6 | Choose Preview to run the report again to verify that the code you entered did not create any errors.

(c) Copyright Actuate Corporation 2013