Add To Collection

The collection package in the designer acts as a container to store information/data during the run time.

We can use the add to collection activity to dynamically store the data from an excel file or a web service in a table format.

Technical Reference Fig (1.1)


 

    

 

     

 

 

MISC

Collection: This indicates the name of the collection variable to which the item has to be added

Display Name: Displays the name of the activity. You can also customize the activity name to help troubleshoot issues faster. This name will be used for logging purposes.

Item: This indicates the name of the variable which has to be added to the collection

TypeArgument: This indicates the type of the argument which is going to be added. There are number of options from which we can choose.


*Mandatory fields to execute the workflow

Example:

Here we are going to automate and demonstrate the utilization of Collections feature. The following activity illustrates on how we are going add a name to the collection of lists.

Variable creation:

1.      From the variable section below, create a variable “Name” as name of the variable and choose the variable type as string. Also add the name “John” to be added to the collection tab in double quotes in Default value.

Fig (1.2)

2.      When we use the add to collections activity, create a variable in the variable box to execute the action.

3.      Create another variable for the collection name for which the item has to be added.

4.      Use “Name_Col” as name of the variable.

5.      In the string type we need to click on Browse types and type System.Collections.Generic.List<T> in the search option. Also choose string from the drop down and this gets displayed as List<String>.

6.      Now choose the default as New list (of string) for the name to be added to the collection.

Fig (1.3)

 

To build the process,

1.     Open a project and create a workflow.

2.     Drag and drop a sequence activity from the ControlFlow feature to the workflow

3.     Double click on the activity.

4.     Create variables for item that is to be added in collection and for the collection activity. Refer fig.1.2 and 1.3.

5.     Drag and drop a write line activity from the primitives feature to the sequence box of the workflow.

6.     Enter the VB expression as “Initial Value:” +Name_Col.Count.ToString , which gives an output of what the value was before adding the item to the collection. 

Fig (1.4)

7.    Drag and drop an Add collection activity below this Write line activity and enter the variables in the property box.

8.    From the properties panel, add “Name_Col” variable in collection tab.

9.    To the Item box add the “Name” variable to add the item to the collection.

10.  In the TypeArgument, we need to choose String from list of drop down as we are going to add string type to the list.

Fig (1.5)

11.  Drag and drop another write line activity Below the Add to Collections activity which will help us to understand if the value has been added.

12.  Enter the VB expression as “Final Value:” +Name_Col.Count.ToString

13.  Set the whole sequence as a start node for this activity and execute the workflow.

Fig (1.6)