Loop - List

Declaration

<AMLOOP ACTIVITY="list" LIST="text" DELIMITER="text (options) RESULTVARIABLE="text" SORT="text (options)" />

Related Topics   

Description

Loops through delimited items in a list. The current index variable is updated with the next item in the list. With each loop the current item in the list is returned. The loop process ends when the last delimited item is reached or when a Break is encountered.

Practical usage

Normally used in conjunction with the Read from file activity to perform operations on delimited text. Note that in certain situations, a Loop file contents activity may be preferable due to the fact that it combines the functionality of both the 'Read from file' and 'Loop list' activities into a single activity.

Parameters

General

 
PropertyTypeRequiredDefaultMarkupDescription
ListTextYes(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 itemTextYes(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.
DelimiterText (options)NoComma
  • DELIMITER="comma"
  • DELIMITER="new_line"
  • DELIMITER="semi-colon"
  • DELIMITER="space"
  • DELIMITER="tab"
The character used to delimit 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.
  • Semicolon - The delimiter is a semicolon (Example: item1;item2;item3).
  • Space - The delimiter is a space (Example: item1 item2 item3). \
  • Tab - The delimiter is a tab character.
  • Custom - The delimiter is another character as specified (enter the desired character in the provided text-box).

Advanced

PropertyTypeRequiredDefaultMarkupDescription
Output list sort orderText  (options)NoNone
  • SORT="none"
  • SORT="ascending"
  • SORT="descending"

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

  • None - No sorting will be applied.
  • Ascending alphabetical order - The list will be sorted in ascending alphabetical order (A-Z).
  • Descending alphabetical order - The list will be sorted in descending alphabetical order (Z-A).

Description

Error Causes

On Error

Examples

NOTE:
  • Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
  • To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.

Example 1

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

Copy
<AMVARIABLE NAME="thenames" VALUE="Dustin,Scott,Jeff,Kirsten"></AMVARIABLE>
<AMVARIABLE NAME="currentitem" VALUE="" />
<AMLOOP ACTIVITY="list" LIST="%thenames%" RESULTVARIABLE="currentitem" />
<AMSHOWDIALOG>%currentitem%</AMSHOWDIALOG>
<AMLOOP ACTIVITY="end" />

Example 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.

Copy
<AMVARIABLE NAME="filecontents" VALUE="" />
<AMVARIABLE NAME="currentitem" VALUE="" />
<AMFILESYSTEM ACTIVITY="read_file" FILE="c:\thelistfile.txt" RESULTVARIABLE="filecontents" />
<AMLOOP ACTIVITY="list" LIST="%filecontents%" DELIMITER="new_line" RESULTVARIABLE="currentitem" />
<AMSHOWDIALOG>%currentitem%</AMSHOWDIALOG>
<AMLOOP ACTIVITY="end" />