Modify collection values

Architect includes functions that help you modify collection values. For example, this expression creates an integer collection with the integers 3 and 4, and then appends the number 5 to it with an AddItem function:

AddItem(MakeList(3,4), 5)

The result of this expression is an integer collection with three items in the following order: 3, 4, 5.

The table below lists functions you can use to modify a collection value. For more information, see Access Expression help.

Method Description
AddItem This function adds items to a collection.
AddItemAt This function adds a new item value to a collection at a specific index.
RemoveDups This function removes duplicate values from a collection.
RemoveItem This function removes one or more items from a collection by value.
RemoveItemAt This function removes an item from a collection at a specific index.
ReplaceItemFirst This function removes the first occurrence of a value in a collection with a new value and returns the resulting collection value.
ReplaceItem This function removes one or more items in a collection and replaces the items with a new value.
ReplaceItemAt This function removes an item in a collection at a specific index and replaces it with a new value.

Examples

A common way to modify a collection value is with an Update Data action. These examples describe ways to add or remove items from a collection.

Add an item to a collection

This example uses a string collection variable called Task.IntegerColl. The objective is to add 6 to the existing 3, 4, 5 output.

  1. Add an Update Data action to the task editor.
  2. Add an Integer Collection update statement, which is the Task.myIntegerColl variable type.
  3. In the Variable Name 1 box, type Task.myIntegerColl.
  4. In the Value To Assign 1 box, type AddItem(Task.myIntegerColl, 6).

The resulting output is 3, 4, 5, 6. You can also add an item to the beginning of a collection. Building on the previous example, AddItemAt(Task.myIntegerColl, 0, 7) results in 7, 3, 4, 5, 6.

Remove an item from a collection

This example uses a string collection variable called Task.myStringColl. The objective is to remove all NOT_SET string values.

  1. Add an Update Data action to the task editor.
  2. Add a String Collection update statement, which is the Task.myStringColl variable type.
  3. In the Variable Name 1 box, type Task.myStringColl.
  4. In the Value To Assign 1 box, switch to the Expression editor and type RemoveItem(Task.myStringColl, ToString(NOT_SET)) or RemoveItem(Task.myStringColl, NOT_SET).

Notice how these examples use the result of the function call in the value to assign, and then assigns the resulting value back to the variable. This process updates the variable’s value. Supply the current collection value of the variable by using the variable in the expression. Upon evaluation, the system assigns the result of the expression back to the variable value.