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.
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:
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.
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.
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.
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
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.
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.
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)
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