How do you create and use a dictionary in GC Workflow 5?
What is the expression to initialise an empty dictionary if I use a Create Value activity? How do I then manually populate it with key-value pairs? Finally how do I check whether a particular key exists and look-up its value?
-
I've managed to figure this out, so to help others here is what I've done.
To create an empty dictionary use this in a Create Value activity:
={}
I wasn't able to figure out how to populate an existing dictionary with key-value pairs, so instead when I created the initial dictionary I populated it then:
={"Key1":"Value1","Key2":"Value2","Key3":"Value3"}
?
To check whether a particular key exists use this in an If activity:
=!$downloadableFormats.result["Key2"]
Note that we're check whether it does not exist, so switch round the True and False sides of your If activity accordingly. It's easier to check whether it does not exist rather than to check whether it does exist.
Finally, to retrieve the value of a particular key (after checking it exists), use this:
=$downloadableFormats.result["Key2"]
0 -
Thanks for providing this information Mark.
There are a number of activities in the Collection section which allow for interacting with dictionary-type objects as well.
0 -
Mark Norbury
Along with your suggestion, if you use standard Javascript object key name formatting (i.e., no spaces, illegal characters, etc.) you can also use this format:
value.result.<keyName> (where "keyName" is the name of your object key)
Ex., =$downloadableFormats.result.Key2
The output is the same, but it saves you a few keystrokes, if you are so inclined, but either way is perfectly valid.
0
Du måste logga in om du vill lämna en kommentar.
Kommentarer
3 kommentarer