Using Collections in Your Interaction

Generally, collections are used in conjunction with allocations, so you can manipulate the values in the collection according to your requirements. Some common use cases include:

Adding a value to a collection

Getting the size of a collection

Accessing an item from a collection

tog_minusAdding a Value to a Collection

In this use case, one or more values are allocated into a simple collection. The values can be either hard coded, or they can be taken from an existing variable. In runtime, the values are added to the end of the collection.

To add values to a collection:

1.At the bottom of the Allocator Definition dialog, click Add Allocation.

2.From the dropdown list on the left side of the Allocations frame, select the relevant collection.

3.From the dropdown list in the center of the Allocations frame, select the Add operation. (By default, only the Add operation is available.)

4.In the field on the right side of the Allocations frame, enter the value to be added to the end of the collection. Alternatively, select the Use existing element checkbox, and then, from the dropdown list, select the relevant element.

Adding Values to a Collection

5.To add additional values, repeat Steps 2-5.

6.Click OK.

The Allocator Definition dialog closes. In runtime, the specified values will be added to the end of the collection.

tog_minusGetting the Size of a Collection

In this use case, the size of a collection (simple or object) is allocated into a number variable.

To get the size of a collection:

1.At the bottom of the Allocator Definition dialog, click Add Allocation.

2.From the dropdown list on the left side of the Allocations frame, select the relevant variable, or create a new variable. The variable type must be Number.

3.From the dropdown list in the center of the Allocations frame, select the Equals operation.

4.Select the Use existing element checkbox. Then, from the dropdown list on the right side of the Allocations frame, navigate to the relevant collection, and select the Collection Size option.

Collection Size Option

5.Click OK.

The Allocator Definition dialog closes. In runtime, the collection size is allocated into the specified variable.

tog_minusAccessing an Item From a Collection

In this use case, an indexed item from a simple or object collection is allocated into a variable. This variable can then be used in another Interaction element (e.g., a Statement).

To access an item from a collection:

1.At the bottom of the Allocator Definition dialog, click Add Allocation.

2.From the dropdown list on the left side of the Allocations frame, select the relevant variable, or create a new variable.

3.From the dropdown list in the center of the Allocations frame, select the Equals operation.

4.Select the Use existing element checkbox. Then, from the dropdown list on the right side of the Allocations frame, navigate to the relevant collection, and select the Indexed Item option.

An additional column appears at the right side of the Allocations frame.

Indexed Item Option

5.In the new field on the right side of the Allocations frame, enter the value of the indexed item. Alternatively, select the Use existing element checkbox, and then, from the dropdown list, select a variable that will hold the value of the indexed item.

6.Click OK.

The Allocator Definition dialog closes. In runtime, the collection size is allocated into the specified variable.