I use For Each to loop through datatable and for each row I search a website and capture the DUNS number as a string variable- ‘DUNS’
How do I turn the DUNS numbers captured into a list and then use the list to search other websites using each DUNS number?
DUNSlist variable is systems.collection.generic.list<system.string>
DUNS variable is string
There is an alternative way (other than using Add To Collection). You can use an activity called Invoke Method
All List type variables can use a .net method called .Add. List<T>.Add(T) Method (System.Collections.Generic) | Microsoft Learn
You can use Invoke Method activity to do many other manipulations so it is a handy activity.
In your case, for example,
DUNSlist.Add(DUNS) will add your DUNS string to your List
In Invoke Method it will look like (you have your DUNS from GetText, I use an assign in my example) with the added parameter:
Also remember to assign your DUNSlist outside the for loop else you will keep generating a new list i.e. each iteration will use New List(Of String) and empty the previous runs.
Here is the sample file : AddToList.xaml (6.0 KB)
Hope this helps you dig deeper into the Invoke Method activity.
You shouldn’t initialize the list (the Assign activity) each time you loop. This empties the list.
Take out the Assign. Put new list(of string) as the default value of DUNSlist. This way it automatically initializes when the job starts.
Now your Get DUNS and Add To Collection activities will work properly and you’ll have what you need. You can use a For Each to loop through DUNSlist (make sure to change the For Each to string instead of object, in the properties pane)
You are almost done
Hope the below steps would help get the list of values
No big changes needed in your step
- Just Remove the assign activity with which we are initialising the list variable
Usually it has to be initialised only one else it will create a new variable in every iteration of loop
So finally we will be having only one value in it
In order to avoid that initialise it once in the variable panel itself
That is in variable we can find a default value column where mention the same definition like this
New list(of string)
- Then in Add to collections mention the output variable of Get text activity to Item property
The list varivale name in collections property name
And change the type property as string
That’s it you are done