vadim.tabakman@nintex.com

Dictionary Part 1 - Manually Creating a Dictionary

Blog Post created by vadim.tabakman@nintex.com Employee on Mar 18, 2015

The Dictionary variable type, although the concept is not new, is new in Nintex Workflow for Office 365 for those who are more experienced with the on-premise version of Nintex Workflow, which instead of a Dictionary, there was a Collection variable.  To move your mind into the concept of the Dictionary, takes a little getting used to when you've being working with the collection (or an array of data).  But hopefully this serious of posts will shed some light on the subject and make it a little easier to grasp and utilize in your business processes.

 

What is a Dictionary?

 

I'm sure most of your have opened a dictionary book before.  Remember those things called books?  Oh wait, ok... http://www.dictionary.com .  You probably know that.

 

The concept of the dictionary is that in effect it's based on Name/Value pairs.  Based on the name, you can pull out the value.  The big difference between the Dictionary variable type and the Collection variable type, is that a collection was only able to hold values of the same type.  A Dictionary have hold all sorts of different variable types at one type.

 

So where with a collection, you would have two collections to store data from a query (eg. Country and State), with the dictionary, it's one dictionary variable.

eg,

Collection1 (Country)Collection2 (State)
USACalifornia


Then, you'd need to use an index to get the appropriate value out of each collection.

The dictionary would look like this:

 

NameValue
CountryUSA
StateCalifornia


Then, you just need the Get an Item from a Dictionary and pass it the name "Country" and it will return USA.  Easy as cake!!

 

Manually Building a Dictionary


This is the easiest way to start working with a dictionary.  Firstly, go to Variables in the workflow designer and create a new Dictionary variable.  Once you have that variable, you can then use the Build Dictionary.  This is the action you use to define the Name/Value pairs.

 

BuildDictionary.png

In the above example, we have 3 name/value pairs where we define the Key and the Value (Country, State and Sport), with default values of USA, Utah and Poker.

Once you have the dictionary built, you can then use that throughout the workflow instance, as a place to store and retrieve data.

Reading data from a dictionary

 

You use the "Get an Item from a Dictionary" action.  With the type of dictionary we have built here, it makes it really easy to be able to get at the data, since you only need to specify the value you want, but the Key name.

GetItemFromDictionary.png

In the above screenshot, we are getting the value of the State from the dictionary, and storing it in a text variable.


Number of Items in the Dictionary


There are times when you need to get the number of items in the dictionary.  In that case, you can use the Count Items in a Dictionary.

CountItemsinaDctionary.png

The above action will the results in an Integer variable.

 

Update a Value in a Dictionary


To update a value in a dictionary, you can use the Build Dictionary action again.  Using this action on the same dictionary will not wipe the dictionary clean.  It will simply set the values of the items based on the Keys you provide.

UpdateDictionaryItem.png

As you can see, we are reusing our "dict" variable, but this time, we're only setting the State items value.  This is extremely important, because you can therefore use this dictionary through the workflow, reading and updating the data all over the place.

Outcomes