How to use dictionaries in UiPath

Hello,

I’m looking to create a dictionary to store specific data I’ll be extracting sequentially. Specifically, I’ll be retrieving codes such as “748201” which will serve as dictionary keys, and corresponding titles like “Invoice of tech department” as their values, but the informationa will be stored in variables like code = “748201” and title = “invoice of tech department”. This process will be repeated multiple times.

For example, i want to do that:

Dictionary = {“748201” = "Invoice Tech Department"´}
{“753921” = "Invoice Marketing Department"´}
{“776201” = "Invoice blabla Department"´}

The key variable is “code” and the value variable is "title

Could you guide me on how to store these keys and values effectively?

Additionally, I’d like to send the contents of this dictionary via outlook email.

Thank you in advance for your assistance.

In UiPath, you can use dictionaries to store and manage key-value pairs of data. Dictionaries are useful when you need to store and retrieve data quickly based on a unique key. Here’s how you can use dictionaries in UiPath:

  1. Create a Dictionary:
    • To create a new dictionary, you need to use the Invoke Code activity or a custom script. UiPath doesn’t have a built-in activity specifically for creating dictionaries.
    • In the Invoke Code activity, you can write VB.NET or C# code to create a dictionary object. For example, in VB.NET, you can create a dictionary like this:

Dim myDictionary As New Dictionary(Of String, Object)

  • You can replace String with the data type of your keys and Object with the data type of your values.
  1. Add Items to the Dictionary:

    • To add items (key-value pairs) to the dictionary, you can use the Add To Dictionary activity.
    • Configure the activity by specifying the dictionary variable, key, and value to add.
  2. Retrieve Items from the Dictionary:

    • To retrieve items from the dictionary, you can use the Get From Dictionary activity.
    • Configure the activity by specifying the dictionary variable and the key you want to retrieve.
    • The retrieved value can be stored in a variable for further processing.
  3. Update Items in the Dictionary:

    • To update the value associated with a specific key in the dictionary, you can use the Assign activity.
    • Assign the new value to the dictionary key. For example:

myDictionary(“KeyToUpdate”) = newValue

  1. Remove Items from the Dictionary:

    • To remove items from the dictionary, you can use the Remove From Dictionary activity.
    • Configure the activity by specifying the dictionary variable and the key you want to remove.
  2. Check if a Key Exists:

    • To check if a key exists in the dictionary, you can use the Contains Key activity.
    • Configure the activity by specifying the dictionary variable and the key you want to check.
    • It will return a Boolean value indicating whether the key exists in the dictionary.
  3. Loop Through Dictionary:

    • To iterate through all the key-value pairs in a dictionary, you can use a For Each loop.
    • Use the Get Dictionary Value activity inside the loop to access the key and value for each iteration.

Here’s a simple example workflow:

1. Create a Dictionary (Invoke Code)
2. Add Items to the Dictionary (Add To Dictionary)
3. Retrieve Items from the Dictionary (Get From Dictionary)
4. Update Items in the Dictionary (Assign)
5. Remove Items from the Dictionary (Remove From Dictionary)
6. Check if a Key Exists (Contains Key)
7. Loop Through Dictionary (For Each + Get Dictionary Value)

HI @Carla_Munoz

Go through this once

1 Like

HI @Carla_Munoz

you can do this way

  1. Take assign activity and Initialize the dictionary
invoiceDictionary = New Dictionary(of string,string)
  1. Take invoke method activity and pass like this
    image
  2. in the properties of invoke method you can pass like this

output : -

note : invoiceDictionary variable type is System.collections.generic.Dictionary(Of String, String)

1 Like

Hi!

The thing is that the values are stored in variables. And the information of the variables are extracted from a website

myDict | DataType: Dictionary(Of String, String) = 
new Dictionary(Of String, String) From{
{"748201","Invoice Tech Department"},
{"753921","Invoice Marketing Department"},
{"776201","Invoice blabla Department"}
}

For more manipulation / accessing options have a look here as well:

One Of Many Options:
String.Join("<br>", myDict.Select(Function (x) String.Format("{0}:{1}", x.Key, x.Value))

We assumed, that the email will be sent as HtmlText, so we used <br> for the line break

HI @Carla_Munoz

After extracting from the web page you are storing the variable suppose like variable 1 and variable 2

you can pass in the invoke method > parameters like this

note : - after extracting the data from web both the code and title present in single line you go for string manipulations and assign values to variable1 and variable2 and pass in the parameters

1 Like

Thank you so much!!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.