Get to Know Your Datatypes: Dictionary Variable

  • 14 April 2021
  • 0 replies
  • 873 views

Userlevel 6
Badge +9

 

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.

  1. Dictionary Creation

    1. 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.
    2. 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.
      1. In the video, the subtype is left as a string, but alternatively, boolean, number, or any could have been selected.
        1. Any as a subtype, suggests that the values stored in this dictionary may be mixed between string values, number values, and boolean values.
    3. Sticking with the suggested Hungarian notation for variable naming, a lowercase d is used as a prefix for the variable name.

  2. Returning the Dictionary Size

    1. Within the Dictionary Package, there is a Size action that returns (as a number) the length of the dictionary provided.
    2. This can be helpful when validating a dictionaries length or establishing looping to iterate through each key/value pair of the dictionary.
      1. 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.

  3. Get/Put/Remove

    1. The flexibility of being able to retrieve, add, and remove key-value pairs from a dictionary is where its flexibility really shines.
    2. Using the Get action, you can return the value found at the location of the provided key, and return that value to a variable.
    3. Using the Put action, you can insert a key-value pair into the dictionary
      1. 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.
    4. Using the Remove action, key-value pairs can be removed from a dictionary based on the provided key.
      1. 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.

Conclusion

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


0 replies

Be the first to reply!

Reply