Search code examples
jsonvariablespower-automate

Initialize Multiple Variables JSON in Power Automate


I'm working on populate a MS Word Template in Power Automate and all responses come from a MS Form. One of the fields in the Word Template is "Abbreviation". I'm trying to figure out a way to pass the dynamic variable of "What is your County" into this field and convert the specific county name into the County abbreviation. Example would be "Washington County": "WC". I thought about using JSON object to do this but can't figure out how to connect the dynamic variable of "What is your County" to each County and County Abbreviation. I've got some screenshots of what I am working on.

enter image description here

enter image description here


Solution

  • It's actually quite straight forward. Using expression, you can pass in the value of a variable into an expression that will retrieve the value of a property in another object.

    This example shows you how to achieve what you're after.

    Flow

    Basically, I've created an object with a set of properties. I've then created a variable who's value is the name of the one of the properties in the object created in the previous step.

    Then in the final step, using this expression ...

    variables('Lookup Object')?[variables('Lookup Property')]
    

    I can get the value, like thus ...

    Result

    If I were to hardcode that expression and be specific, it would look like this ...

    variables('Lookup Object')?['Property 2']
    

    ... and that’s what you’re trying to avoid.