Can we add more than one key-value pair to dictionary using invoke method

Hi,

Can we add more than one key-value pair to dictionary using invoke method, I did try adding the second element and it gives me below error
Error ERROR Validation Error ‘Dictionary`2’ does not have a public instance method named ‘Add’ matching the parameter types, generic type arguments, and generic type constraints supplied to InvokeMethod ‘Invoke Method’. List_Ex_Demo.xaml

Below is my setup, Could somebody point me in the right direction.

Hi @mcashwin,

You can use loop for this.

  1. Create the table you want to add.
  2. Use table in loop
  3. Add currentrows to parameters.

Regards,
MY

Hello muhammedyuzuak,

Thanks for your response, Well actually Cant we achieve it without loops or datatable, As I understand we can add key value pairs to dictionary using

  1. Add To Collection
  2. Invoke Method -Add
    But using the above methods cant we add more than one key-value pairs into the dictionary by passing all the pairs using just one method, for eg In invoke method or Add to collection parameters can we not add more than one parameter?

Hi,

Dictionary.Add method can have only single key and value, as the following document.

If we need to add multiple key-value pairs in single statement, the following might help you, for example.

dict = dict.Concat(New Dictionary(Of String,Int32)From{{"Teacher",3},{"Doctor",3}}).ToDictionary(Function(kv) kv.Key,Function(kv) kv.Value)

Regards,

Hello Yoichi-san,

Thanks for your reply, it does makes sense, What confused me and still makes me think is the parameters section still allows us to key in more parameters when there is a limit for just for one key-value pair.

image

Hi,

Unfortunately, parameter dialog doesn’t consider how many arguments can be set to the method. So, we need to set proper arguments from specification of the method.

Regards,

Hey @mcashwin

You need to call the invoke method again or add it in a loop.

Else you can initialize the dictionary directly in an Assign statement,

dict_Data = New Dictionary(Of Integer, String) From {{ 1, "Test1" }, { 2, "Test1" }}

Thanks
#nK

Yeah I was able to do that, what I was trying to achieve was by trying to add keys and values using the parameters in add invoke method, which as Yoichi-san mentioned there is a limitation to add just one parameter.

Hey @mcashwin

It’s not a limitation but the Add is only allowed to accept one set of key value pairs as if required for multiple key value pairs we can loop through same function or look for alternative methods !

Hope that helps

Thanks
#nK