How to manipulate Dictionaries

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. This process will be repeated multiple times.

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.

:ambulance: :sos: [FirstAid] Migration to Windows target Framework - Missing Microsoft.Activities.Extensions package - Dictionary Activities - News / Vote on Tutorials - UiPath Community Forum

myDict = new Dictionary(Of String, String)
myDict("748201") = "Invoice of tech department"
1 Like

@Carla_Munoz

If you need to reassign some value for a key in dictionary then use dict["Key"] ="Value"

the above replaces the previous value and can use same key for all the similar values you want to update

Also it would be a good idea to consider using datatable as well…with look up table activity

cheers

1 Like

Hi @Carla_Munoz ,

Key = “748201”
Value = “Invoice of tech department”

dicVar will be Dictionary<String,String> and initialize new Dictionary(Of String, String)

Use assign activity,

dicVar(Key) = Value

For outlook mail"

bodyContent = “Your Value is: {0}”

String.Format(bodyContent,dicVar.Value)

Thanks!

1 Like

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.

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.

Hi

First initialize a dictionary variable using assign activity like this

myVariable = new Dictionary(Of String,String)

Then assign your key and value like this in assign activity itself

assign myVariable("RANKED") = "ONE"

You can use the same format in assign activity so the dictionary variable gets built every time when repeated

On this part

You can send that dictionary as a datatble with key and value as two columns
Steps involved are

  1. Build data table with two columns key and value.
  2. For each loop for dictionary
  3. for each item Add data row ArrayRow{item.key, item.value} output of build data table

Now u can send this directly as a table in mail or as a excel file by writing to excel with write range workbook activity

Hope this helps

Cheers @Carla_Munoz

1 Like

HI,

If your source is datatable (worksheet), the following expression may help you.

dict = dt.AsEnumerable.ToDictionary(Function(r) r("KeyColumn").ToString,Function(r) r("ValueColumn").ToString)

note : dict is Dictionary<string,string>type. dt is DataTable type

Regards,

I’ve merged very similar topics together