CA Process Automation supports the JavaScript length property for arrays and its own size property for accessing the length of an indexed field. The length property is read-only; the size property lets you change the number of elements in an indexed field. The length property uses either dot or bracket notation to return the number of elements in an indexed field:
dataset_reference.indexed_field_name.length
dataset_reference[indexed_field_name_expression].length
The size property works the same way, using either dot or bracket notation:
dataset_reference.indexed_field_name.size
dataset_reference[indexed_field_name_expression].size
Because an indexed field is a zero-based array, the length and size properties always return one more than the index for the last element in a field. Therefore, when length or size returns n, a field contains 0, 1, ..., n-1 indexed elements, and the index for the last element in the array is n-1.
Assigning a new value to the size property extends or truncates the number of elements in an indexed field. Decreasing the value for the size property removes elements from the upper end of an indexed field and deletes values stored in the deleted elements. The following code uses the size property to increase the length of an array X by one element, then assigns 25 to the new element:
Process.X.size = Process.X.size + 1; Process.X[Process.X.size - 1] = 25;
For a multidimensional array, the size or length property returns the number of elements in an array address to which it is appended.
For example, for a two-dimensional array named matrix[a][b], the following syntax returns the size of the first dimension of matrix, with the containing elements 0...size1-1:
size1 = matrix.length
The following syntax returns the size of the second dimension of matrix, given first dimension element 2, with b containing elements 0...size2-1 when a = 2.containing elements 0...size1-1:
size2 = matrix[2].length
The following example addresses elements of a multidimensional indexed field by looping through all elements in a two-dimensional indexed field (an array of arrays) in the process dataset variable named matrix. The code assigns the value for each element to a one-dimensional indexed field in the process dataset variable named values:
var i; j; k=0;
for (i=0; i < Process.matrix.length; i++)
{
for (j=0; j < Process.matrix[i].length; j++)
{
Process.values[k] = Process.matrix[i][j] k++
}
}
|
Copyright © 2014 CA.
All rights reserved.
|
|