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.
2 From the list of available scripts at the top of the script window and select onCreate, as shown in Figure 23-8.Figure 23-8 onCreate( ) in the script windowNotice 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.
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( )
6 Choose Preview to run the report again to verify that the code you entered did not create any errors.
(c) Copyright Actuate Corporation 2012 |