This product version has reached end of life and is no longer supported. Click here for the latest documentation.

A List is a sequence of elements of the same data type, which may contain duplicate values. Elements can be inserted, fetched and removed from a list.

By default a list is empty, meaning that it has no elements. However, you can use the system actions to manipulate an empty list.

Iterate a List

To iterate through the elements of a List, use a For Each :

  1. Add a For Each to your logic;
  2. Set its 'Record List' property with the list you want to iterate;
  3. Create a loop around the For Each with the logic you want to execute for each element of the list. In For Each logic, you can access the current element of the list using <List>.Current .

You can't add or remove elements to a list while iterating it. This raises an exception.

If you want to access a specific element of the list with an index, you can do it using <List>[<index>] .
Make sure you use valid values as index, otherwise you'll get a runtime error. To do so, use List.Empty and List.Length runtime properties.

Runtime Properties

When a List is created, OutSystems Platform provides you with the following runtime properties:

Property

Type

Access type

Comment

Current

List element type

Read/write.

Allows direct access to the current element.

EOF

Boolean

Read only.

Indicates whether the end of the list was exceeded. When you are iterating the last element, this property is still FALSE.

BOF

Boolean

Read only.

Indicates whether you are at the beginning of the list. When you are iterating the first element, this property is True.

CurrentRowNumber

Integer

Read only.

The index of the current element in the list, starting with 0.

If the list is empty, this property is 0.

Length

Integer

Read only.

The number of elements currently in the list.

Empty

Boolean

Read only.

Indicates whether the list is empty.

List Operations

The following System Actions are available to manipulate a List:

System Action

Description

ListAppend

Adds an element to the end of a list.

ListAppendAll

Adds the elements of the source list to the end of the destination list.

ListClear

Removes all elements from the list.

ListDuplicate

Duplicates the contents of a list into another list.

ListInsert

Inserts an element in a specific position of a list.

ListRemove

Removes an element from a specific position of a list.

Remarks

Variables of List data type have a reference to the values, so don't contain a copy of the elements.

Example

You have two lists, one with the customers from Philadelphia, named 'PhiladelphiaCustomers', and other with the customers form New York, named 'NewYorkCustomers'. If you assign the 'PhiladelfiaCustomers' to the 'NewYorkCustomers' list you will have two variables pointing to the same list of customers instead of two independent copies. So when changing values in one variable, the other is also changed.

See Also

Overview of System Actions and Functions | Available Data Types