Zum Hauptinhalt gehen

How do you create and use a dictionary in GC Workflow 5?

Kommentare

3 Kommentare

  • Mark Norbury

    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
  • Stefan Schweigert

    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
  • Randy Casey

    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

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.