Loop List Action Icon

Loop List

Declaration

<AMLOOP TYPE="LIST" LIST="text(delimited list)" RESULTVARIABLE="text" DELIMITER="text(options)" SORT="text(options)">

See Also

Loop | End Loop | Loop Files | Loop Windows | Loop Processes | Loop Expression | Loop Dataset | Loop List | Loop List Control | Loop Processes | Loop Tree Control | Loop Windows | Break

Description

Loops through items in a list (comma, carriage return, or other delimited text). With each successive loop a block of steps is executed and the current index variable is updated with the next item in the list. The loop ends when at the end of the list or when a Break is encountered.

Practical Usage

To loop a block of steps through the records (rows) in a list (which is a variable containing multiple rows of data). With each loop the current record (row) in the list is incremented, until the last row is reached at which point the loop is ended.

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

List

Text

Yes

(Empty)

LIST="Item1,Item2,Item3"

The list of data to Loop through. The List can be delimited by a variety of characters.

Populate variable with list item

Text

Yes

(Empty)

RESULTVARIABLE="varname"

The name of the variable to populate with the current list item. With each successive loop, this variable will be populated with the next item in the list.

Delimiter

Text (options)

No

Comma

DELIMITER="semi_colon"

Specifies the character that delimits the items in the list. The available options are:

  • Comma: The delimiter is a comma (Example: item1,item2,item3).

  • New line: The delimiter is a new line.

  • Semi colon: The delimiter is a semi colon (Example: item1;item2;item3).

  • Space: The delimiter is a space (Example: item1 item2 item3).

  • Tabulation: The delimiter is a tab character.

  • Custom: The delimiter is another character as specified (simply enter the desired character).

 

Advanced Properties

Property

Type

Required

Default

Markup

Description

Output List

Text  (options)

No

Do not sort the list

SORT="ascending"

Specifies whether a sort order should be applied towards the list before the loop begins. The available options are:

  • Do not sort list (default)

  • Sort the list in ascending alphabetical order

  • Sort the list in descending alphabetical order

 

Description Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab properties lets you instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Additional Notes

Expressions, Variables & Functions

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, functions and other expressions to be entered in any text parameter of a task's properties. For example: %1+1% inside a task will resolve to 2 at runtime. A more elaborate example is %FileDateTime(myFile)% which results to the date/time of myFile. To help construct expressions, you can open Expression Builder by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on functions

More on extended functions
More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 

Sample 1 - This task loops through comma delimited text and displays each delimited item in a message box during each loop process.   

 

<AMVARIABLE NAME="thenames">Dustin,Scott,Jeff,Kirsten</AMVARIABLE>

<AMVARIABLE NAME="currentitem"></AMVARIABLE>

<AMLOOP TYPE="LIST" LIST="%thenames%" RESULTVARIABLE="currentitem">

     <AMMESSAGEBOX>%currentitem%</AMMESSAGEBOX>

</AMLOOP>

 

 

Sample 2 - This task shows reading in a file with multiple lines. Each line of the file is treated as a list item. To use it, you must create a  text file called c:\thelistfile.txt and add a few lines of text to it.

 

<AMVARIABLE NAME="filecontents"></AMVARIABLE>

<AMVARIABLE NAME="currentitem"></AMVARIABLE>

<AMFILEREAD FILE="c:\thelistfile.txt" RESULTVARIABLE="filecontents" />

<AMLOOP TYPE="LIST" LIST="%filecontents%" RESULTVARIABLE="currentitem" DELIMITER="new_line">

     <AMMESSAGEBOX>%currentitem%</AMMESSAGEBOX>

</AMLOOP>

 

↑ Top of Page