Skip to main content
Skip table of contents

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:
"ExitLoop": break loop and continue with script
"Next": continue to next loop action item

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
<OnError continue="false"/><!-- general error setting breaks automation - loop OnError has priority -->
<loop list="MyList" OnError="Next"><!-- within the loop, an error will make it progress to the next action item -->

XML
<ytriaAutomation>
    <!--make a list of databases to load-->
    <List name="MyList" Action="Load" Database="AutoTest\lm_us_8.nsf" Server="ytest-MD/TESTING"/>
    <List name="MyList" Action="Load" Database="AutoTest\lm_nab_8.nsf" Server="ytest-MD/TESTING"/>
    <List name="MyList" Action="Load" Database="AutoTest\custinfo_s03.nsf" Server="ytest-MD/TESTING"/>
    <List name="MyList" Action="Load" Database="websecuritystore.ntf" Server="ytest-MD/TESTING"/>
    <List name="MyList" Action="Load" Database="YtriaLogFile-2013-03.nsf" Server="ytest-MD/TESTING"/>
    <Overwrite value="false"/><!--to get exported HTML file name increment (otherwise each iteration overwrites the file)-->
    <OnError continue="true"/><!-- general error setting - loop OnError has priority -->
    <!--run & export doc analyzer for each database in the list-->
    <loop list="docanalyzer" OnError="Next">
    <ExecuteListAction/> <!-- LOAD executed here -->
    <DocumentAnalyzer>
        <SetParam field="TreeOptions" value="CategoryFields"/>
        <SetParam field="TreeOptions" value="CategoryEncryptionNotEncryptedSecret"/>
        <SetParam field="TreeOptions" value="CategorySummarized"/>
        <SetParam field="DesignElements" value="true"/>
        <Export>
            <SetParam field="FilePath" value="D:\temp-exports\scanEZ-DocAnalyzer.html"/>
            <SetParam field="ExportType" value="HTML"/>
        </Export>
    </DocumentAnalyzer>
    </loop>
</ytriaAutomation>

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
<OnError continue="true"/>
    <loop list="MyList""><!-- onError not set -->
    </loop>

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.

CODE
<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>
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.