Task 3: Conditionally increment the counter in the Row.onCreate( ) methodTo count the number of customers with the string Mini in their names, you must 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 with every retrieval of a row of data from the data source.
2 Pull down the list of methods at the top of the script window and select onCreate, as shown in Figure 23‑8.
Figure 23-8 onCreate( ) in the script windowrow_Data = this.getRowData();Notice that when you enter the period after this, a pop-up appears containing all the available methods and properties, including getRowData. 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=row_Data.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 mCount = countOfMinis.intValue();mCount += 1;countOfMinis = new Packages.java.lang.Integer(mCount);reportContext.setPersistentGlobalVariable("cmKey", countOfMinis);}You can use the JavaScript palette to insert each of the following elements in the preceding lines:
n indexOf( )Select Native ( JavaScript ) Objects->String Functions->indexOf( )
n Select Operators->Comparison->!=
n 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 2008 |