Loop: iterate over a list
Tag: Loop
The Loop function iterates over a previously set LIST of actions, executes the listed action, and executes all other actions set within the LOOP (same as a "For Each" or "ForAll" in standard programming languages).
Tag Attributes
Attributes | Value Description |
---|---|
List | Name of the list to process |
OnError | Action to take in case of error within LOOP block: |
RemoveListItemUponErrorOn | Removes list action from list upon error. Accepted values are: All: all actions in the list ListAction: action in current iteration |
Example Script
Loop OnError has priority over the current OnError action. In this example, the script is supposed to stop when an error is raised, but this will be ignored within the loop, which will continue with the next action item from the list it's processing:
XML
|
XML
|
The LIST is not automatically cleared after the LOOP is executed.
When OnError is not set at the loop level and set to true at script level...
XML
|
Then an error on the list action skips the entire iteration and the loop resumes to the next item in the list, as if OnError="Next" was only set for the list action.
When RemoveListItemUponErrorOn is set to ListAction, the action with an error is removed from the list:
List action #3 results in error (the database does not exist) RemoveListItemUponErrorOn removes it from the list and it's not executed in the second loop.
<ytriaAutomation>
<onerror continue="true"/>
<!--echo mode="false"/-->
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest5.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest1.nsf"/>
<!-- error -->
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\zer.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest4.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest3.nsf"/>
<List name="MyList" Action="Load" server="MAINR5/YTRIA" database="mail\atest2.nsf"/>
<loop list="MyList" RemoveListItemUponErrorOn="ListAction">
<ExecuteListAction/>
<echo value="{%LoopIndex%}/{%listSIZE%}"/>
</loop>
<echo value="---------------------------------------------------"/>
<echo value="------------------- SECOND LOOP -------------------"/>
<echo value="--------------------without entry 3 ---------------"/>
<loop list="MyList">
<ExecuteListAction/>
<echo value="{%LoopIndex%}/{%listSIZE%}"/>
</loop>
</ytriaAutomation>