Configuring the For Each node
The For Each node is grouped with Data activity nodes.
- Select the For Each "start" node.
-
On the General tab, select the type of input (Iteration, Expression, Array, or XML). Perform the configuration that corresponds to the type of input you are using:
Iteration Specify the number of loops.
Output variable:
NodeName_iterationNumber will have the value of the each iteration and will be available to use by the nodes inside the For Each loop
Expression This input type is the most similar to a classic for or while loop as it exists in most programming languages. Expression takes three JavaScript expressions as input: Initial Expression, Expression, and Post Expression.
Initial Expression
Takes the initialization of the expression where (<any variable name> = <any number>
Example:
i=1, i=0, j=3 or variable=1
Anything other than initialization in this field will result in error while the process is running. The variable, the value of the variable, or the entire expression can be a variable that is defined in a Start or Assign node.
Expression
takes the condition evaluation of the expression where <variable defined in initial expression> (>,<,==,>=,<=,!=) <any value>
Example:
I < 10, j>=10, variable!=0
This expression must return true or false. Any other response results in error while the process is running.
Only the variable which is defined in the Initial Expression can be used here. If this expression returns true then the nodes inside the For Each node will be executed, otherwise the loop will terminate.
The variable, the value of the variable. or the entire expression can be a variable that is defined in a Start or Assign node.
Post Expression
Takes the incremental expression something where <variable defined in initial expression> (++, + =,--,-=) <any number>
Example:
i++, I = i+2, j= j-2
Anything other than the Incremental Expression here will result either in an error or will cause infinite loop while the process is running.
Only the variable which is defined in Initial Expression can be used here.
The variable, the value of the variable, or the entire expression can be a variable that is defined in a Start or Assign node.
Output variables:
-
NodeName_iterationNumber will have the value of the each iteration and will be available to use by the nodes inside the ForEach loop.
-
NodeName_<variable name defined in initial expression> will have the incremental values of the defined variable.
Array Takes an array of values as input and loop over until the length of the array.
Array of values can be directly defined in the input field using the JavaScript array syntax which is also being used in start and assign node. The array can have any data type which is supported by JavaScript.
The array input can also be a variable. Array input can be [1,2,3,4] or new Array(1,2,3,4).
Output variables:
-
NodeName_iterationNumber will have the value of the each iteration and will be available to use by the nodes inside the For Each loop.
-
NodeName_arrayValue will have the value of the array and will be available to use by the nodes inside the For Each loop.
XML Element Takes XML schema as input, loads all the elements from the schema and displays it in a drop-down box which can be selected to loop over the XML file.
Another input to this is XML data which has to be looped over. All the attributes of the element, child elements and attributes of child elements will be available to the nodes inside the For Each based on what element is selected to loop over.
The XML input can also be a variable.
Output variables:
-
NodeName_iterationNumber will have the value of the each iteration and will be available to use by the nodes inside the ForEach loop.
-
NodeName_<Element Name> will have the value of the element.
-
NodeName_<Element Name>_<child Name> will have the value of the child if the child is the simple type, otherwise it will have the XML fragment as the value.
If any child element variable returns more than one value then it will be in array.
Example 1
<Employee> <Name> John Smith</Name> <Sex> Male </Sex> <DOB> 01-01-1980</DOB> <Designation> Consultant </Designation> <Address> abc </Address> <Dependent type="spouse"> <Name>Karen Hartman </Name> <Sex> Female </Sex> <DOB> 01-01-1982</DOB> <Address> abc </Address> </Dependent> <Dependent type="son"> <Name>Peter Russel </Name> <Sex> Male </Sex> <DOB> 01-01-2010</DOB> <Address> abc </Address> </Dependent> <Education> <Description> Master of Science </Description> <School> Hill City High School</School> <College> Minnesota State University</College> </Education> </Employee>
Example 2
If Employee has been selected as element name to loop over, then the following variables will be available to select from variable list.
In this case, Loop 1 looks like this:
NodeName_Employee - NodeName_Employee_Name – John Smith NodeName_Employee_Sex – Male NodeName_Employee_DOB- 01-01-1980 NodeName_Employee_Designation – Consultant NodeName_Employee_Address – abc NodeName_Employee_Dependent - [<Dependent type="spouse"> <Name>Karen Hartman </Name> <Sex> Female </Sex> <DOB> 01-01-1982</DOB> <Address> abc </Address> </Dependent>, <Dependent type="son"> <Name>Peter Russel </Name> <Sex> Male </Sex> <DOB> 01-01-2010</DOB> <Address> abc </Address> </Dependent>] NodeName_Employee_Education - <Education> <Description> Master of Science </Description> <School> Hill City High School</School> <College> Minnesota State University</College> </Education> If Dependent has been selected as element to loop over then following will be the variables and values available inside the loop. 1st loop NodeName_Dependent – NodeName_Dependent_type - spouse NodeName_Dependent_Name – Karen Hartman NodeName_Dependent_Sex – Female NodeName_Dependent_DOB - 01-01-1982 NodeName_Dependent_Address – abc
Loop 2:
NodeName_Dependent – NodeName_Dependent_type- son NodeName_Dependent_Name – Peter Russel NodeName_Dependent_Sex – Male NodeName_Dependent_DOB - 01-01-2010 NodeName_Dependent_Address – abc
-
-
On the On Error tab, specify this information:
- What should happen on an error?
-
Select from the available options.
- Notify
-
Select the check box if you want to send a notification when an error occurs. If this option is selected, you must fill out the notification details.
- Custom log entry
-
Select the check box if you want a custom log entry in addition to the system-generated log entry.
-
Select the For Each "end" node. On the Break Condition tab, specify any valid true/false conditions that must be satisfied if you want to end the iteration.
Note:
If a variable is used as part of the condition, you must remove the surrounding brackets ("<!" and ">").