Instead of using the built-in CurrentLoopIteration and OverallLoopDuration system variables, you can create custom loop variables and manage them yourself. Previous versions of CA Process Automation required this method. For example, you could create logic to calculate the duration from the start time of the first iteration of a loop to the current time for each loop. You could even use pre and post execution code to set up input into a loop such as
To loop through all the elements of an indexed dataset field, first use a Run JavaScript operator in the Utilities group to initialize the CurrentIndex element for the dataset field to 0. For example, the following expression initializes the CurrentIndex element on the process variable X to 0:
Process.X.CurrentIndex=0;
To loop through indexed elements of a dataset field
Process.X.Size.
Process.X.CurrentIndex=Process.X.CurrentIndex+1;
In this case, the CurrentIndex element is the counter for the loop. You can use the CurrentIndex setting to access elements of the indexed field in calculated expressions. For example:
Process.X[Process.X.CurrentIndex];
Note: If you are accustomed to programming languages such as Visual BASIC that use one-based arrays, remember that an indexed dataset field is a zero-based array. In one-based arrays the first element is indexed by 1 and the last element is indexed by the number of elements. The first element of an indexed dataset field is indexed by 0 and the last element is indexed by one less than the value of the Size element for the field.
In addition to accessing elements in an indexed dataset field, you can track the iteration number during loop processing for other purposes. Use a process variable such as process.i for the index variable. In an Interpreter Module Calculation operator that precedes the looped operator, initialize the process variable to its starting value. For example, process.i=1. To increase the index variable after completing each iteration of the loop, use an expression in the post-execution code for the operator. For example:
Process.i=Process.i+1;
Note: The steps in this topic are considered no longer necessary; however, they are included for reference with legacy code. If using the newer system variables, only step 2 applies and step 3 is replaced as follows. Use the CurrentLoopIteration variable of the looping operator to access elements of the indexed field in calculated expressions. For example:
Process.X[Process[OpName].CurrentLoopIteration];
|
Copyright © 2014 CA.
All rights reserved.
|
|