I was toying with the idea of creating a dictionary variable in Power Automate, and, it seems, I got onto something. Unless there is an easier way?
Well, just for the sake of experiment, what if we wanted to count the number of accounts per owner in our Dataverse instance and store those numbers in an object variable like this:
There are only a few expressions we need to work with to get this done:
setProperty(<object>, <property name>, <value>) – this one will set object property value
variables(‘Dictionary’)[‘PROPERTY_NAME’] – this one will give us object’s property value, though that value has to be there already
And, if we wanted to test whether the property already exists, we could just use string() function to convert object variable to a json string, and, then, use “contains” condition. Like this:
The only other thing to consider is that we can’t use setProperty to update the same variable on which we are setting that property. So, I used two variables. The “Dictionary” itself, and another one, “TempDictionary”. Then I can use setProperty with the “Dictionary” variable and assign expression results to the “TempDictionary”. Then I can use “TempDictionary” variable to update my “Dictionary” variable. It’s kind of awkward, but…
Anyway, the Flow below will iterate through all Dataverse accounts, extract owner name for the “current” account, check if there is a counter for that owner already, increment it if it’s there or add a counter and set its value to 1: