A dictionary is a data type available in Automation 360 that enables developers to store, retrieve, and iterate through key-value data pairings. Dictionaries can be very helpful in reducing the number of variables that need to be created, as a single dictionary value can hold a large amount of data that can be referenced in most all bot actions. In this session, we’ll seek to understand how a dictionary variable can be created in Automation 360, how data can be stored in them, and how we can retrieve data within other actions.
Dictionaries in Automation 360 are created in the same way other variables are created – by clicking on on the ‘+’ sign in the variables pane of the developer interface.
Unique to dictionaries, however, is that a user can define a subtype for the dictionary – to say that the values stored in this dictionary will always be of this particular subtype.
In the video, the subtype is left as a string, but alternatively, boolean, number, or any could have been selected.
Any as a subtype, suggests that the values stored in this dictionary may be mixed between string values, number values, and boolean values.
Sticking with the suggested Hungarian notation for variable naming, a lowercase d is used as a prefix for the variable name.
Returning the Dictionary Size
Within the Dictionary Package, there is a Size action that returns (as a number) the length of the dictionary provided.
This can be helpful when validating a dictionaries length or establishing looping to iterate through each key/value pair of the dictionary.
As a side note, while there may be cases to determine size and loop through the dictionary based on length, typically we would suggest using the Loop package and using the dictionary iterators available therein to loop through each key or each value in the dictionary.
The flexibility of being able to retrieve, add, and remove key-value pairs from a dictionary is where its flexibility really shines.
Using the Get action, you can return the value found at the location of the provided key, and return that value to a variable.
Using the Put action, you can insert a key-value pair into the dictionary
Keys in a dictionary must be unique – that said, if you perform a put into a key-value pair that already exists, the value of the original key-value pair would be replaced by the put action. The previously stored value is returned into a variable as a result of this action should you need to maintain/identify if a value was previously present.
Using the Remove action, key-value pairs can be removed from a dictionary based on the provided key.
Similar to using the put action, the previously stored value found at the key indicated for removal is returned to a variable should you need to evaluate it.
Variables enable bots (and the data they store/use) to be much more dynamic. It can surely feel intimidating to use variable types that you may not have used before or may not be as comfortable with but follow along with the video above, practice setting up and retrieving values from your own dictionaries, and the dictionary variable type will be another tool you can use in your pursuit of automating manual tasks in no time!
If you enjoyed this content and want to take it further, head over to the RPA training materials at Automation Anywhere University. Choose from a rich library of online courses, role-based learning trails, and instructor-led training classes leading to industry-recognized RPA certifications. Additionally, you may consider taking a look at some of the other posts in the Get to Know Your Datatypes series like the Get to Know Your Datatypes: Number Variables