Change variable name based on count

Hi Everyone

I have a variable named Category_List variable which gets items added to it using “Add to Collection”.

For example the list is:

Cat1
Cat2
Cat3
Cat4
Cat5

Is there a way of letting UiPath make the variables automatically based on the list with a for loop or a simplar way?

It is not possible to create variables at the run time. This is because as per the .net compiler all variables has to be known at the compile time. Because of this we can’t create variables at the run time.

But if you are looking for assigning the variable based on some condition, go with switch case or if else.

Regards,
Karthik Byggari

I have another variable that has count value of row from ExtractData variable.

So i wanted each of the list items in its seperate variable such as Category + " Count "

Is it possible to Assign Activity with a Variable + Counter_Number ?

@CGhoST
as mentioned the variable has to be declared before compiling. Maybe a dictionary will help you for this, as the key can be constructed as by Name + Counter_Number

1 Like

I am a new to UiPath and learning as i go. Could you please show how to do this.

Thanks

As I said earlier not possible.

As @ppr suggested you can do with dictionary.
Dictionary contains key/value pairs (1-1 mapping). The key will be unique. And you can access the values of particular key from the dictionary.

Here is the sample workflow for creating dictionary, adding key/value pairs and accessing the dictionary.
Community.xaml (5.4 KB)

Regards,
Karthik Byggari

1 Like

Thank you for the example. I will try to understand it.

Is there a way to make rows in the list into columns?

Also i was thinking if Variables are already defined say for example:

Counter1
Counter2
Counter3
Counter4
Counter5

Is there a way of of adding number in front of variable name as above?

Such as Assign to Variable:

Counter + " Count " = Cat1

Unfortunately no.
It considers two separate strings and will concatenate but not assumes as variable.

Regards,
Karthik Byggari

1 Like