Add string to List of Strings using Invoke method

Hi,

I want to add strings in list of strings at run time. I want to use invoke method activity.

Can any one guide me? is there any other option for doing this?

Thanks,
Vishal

Hi @vishalgajjar11,

UiPath provides the Add to Collection activity which basically do the same.

But if you do prefer to use the Invoke Method activity , it would be something like this:

image

Main.xaml (6.1 KB)

4 Likes

Thank you for the help…:slight_smile:

1 Like

Hello.

It is possible to add a new value to a specific index of that list of strings?

Thanks!

Hi! @tiagofreire you can use the insert method to add items into the list at particular index.
I’ve edited the above worklow:
Main (9).xaml (6.6 KB)

Tell me if this helps!
Regards

Niket Ghai

1 Like

Awesome!

Thank you, @Niket_Ghai!

1 Like

Could you please mark it as solution :slight_smile:
It will help others to see what the answer was!
Thanks!

I can’t see the button to mark it. Maybe only the thread owner can do it?

Hi! It’s okay. yeah only the thread creator can mark as solution. You were right :slight_smile:
Anyway. Thank you.
Happy Automation

I didnt understand Insert function you used, there was no index anywhere mentioned.

Also how can we add multiple items in a list

You can add multiple items by using a foreach loop and placing the insert/add function in it!
And in the parameters property of Insert function we are providing the index!

Regards
Niket Ghai

1 Like

I took a List of type String and assigned some default values to it and took a invoke method what is the target type means in Invoke method?
when i click on the parameters and pass one parameter i dont see any error. and it runs successful and i am able to see string data in output panel.
when i am trying to enter multiple parameters i am getting error, PFA screenshot.

Hi Niket,

Could you please share the XAML file. I tried but couldn’t able to get it.

Can’t believe there is no support for assign with no Lvalue expression. Instead have to invoke code.

Hi Guys,
I came across this and I was wondering if there is a better way for adding multiple strings to a list without using a for each loop.

So before sharing the XAML file for the solution let just explain once again how the activity invoke method works.

What you need to do for it to work is three things:

  1. Write the variable name that you want to perform the method on in the “TargetObject” property.
  2. Write the method name in the “MethodName” property.
  3. In properties panel in the parameters add collection that should contain the arguments that the method should work with (you must make sure how much and what type of arguments your method accepts, if two arguments than each one one of them must be on a specific line)

For this specific case you need to use AddRange with a single argument of the type IEnumerable<String> where its value should look like this {“Str1”,“Str2”,…}

Finally here is a XAML file illustrating all I said: InvokeMethodAddStrings.xaml (8.0 KB)

Regards,
Reda

2 Likes