Adding Items to a Collection and Print Those Items

,

Description: You are building an automation and would like to build a list of items and print out the elements of that list. This is helpful if you would like to build a list of string, int, etc.

Building the solution: his will be a very simple automation to build that can be used regularly. You will need the following elements from UiPath:

  • Add To Collection activity

  • Assign Activity

  • Message Box activity

Required packages: N/A

Building the Automation: To begin building your automation, you will need to drag an Add To Collection activity to your workflow. In the image on the right, select your type Argument first and then create a variable in the Collection field. **(This way, you don’t have to change the collection variable if you choose to have a different type other than the default)

image
image

Next you will need to add an Assign workflow before your Add To Collection node in order to initialize your collection. Your assign value should have the name of your collection on the left and on the right, the assign to value should be: new List(of string)

image

Finally, in order to print all of the items of your list combined, add a Message Box node with the following text: "String.Join(Separator Indicator,Your List Variable)

Ex. For a list named, MyList or type string, if I wanted to separate each string by the “comma”, it should look like this: String.Join(",", MyList) ← Goes within a Message box in order for you to see the values.

If MyList values were: [“apple”, “orange”, “pear”], after running the MessageBox code above, the return value would be: apple, orange, pear

Add Items to a Collection and Print Those Items.docx (28.3 KB)