Data table to dictionary

I have data table and I want to add it to dictionary and then get the values in an argument. Help required please

Hi @Amrita,

Please remember that a dictionary is a collection of key and value pair. When creating the argument please define the type of key and type for value, for my example I’ll use Key as string and value as string.

  1. Since you mentioned you wanted the dictionary as an argument, create an out argument out_dictTest of type dictionary<string,string>

  2. Using a For Each Row iterate thru the data table

  3. Inside the loop, add an activity “Add to Dictionary” and select the dictionary type for key (string) and value (String)

  4. Assign the value to the
    Dictionary = out_dictTest
    Key = select the column you would like to assign as the unique key. row("Job_Id").Tostring()
    Value = Assign the value column. row("Total").ToString()

Hope this helps you, Happy Automation!

Regards,
PD

This is the error I am getting:

PBB_STB_Extract_from_PreCleanseTemplate has thrown an exception

Source: Add to dictionary

Message: Value cannot be null.
Parameter name: Dictionary

Exception Type: ArgumentNullException

System.ArgumentNullException: Value cannot be null.
Parameter name: Dictionary
at UiPath.Core.Activities.ScopeActivity.OnFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.Invoke(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
at System.Activities.Runtime.FaultCallbackWrapper.FaultWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

your dictionary is not getting any results.
can you copy your file here.

The error message points to the Dictionary parameter of the Add to Dictionary activity. Ensure that the dictionary variable is passed here:
image

Regards,
PD

2 Likes