web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

Issue accessing property of an object with a dynamic value

(0) ShareShare
ReportReport
Posted on by 2

I've run into a problem that's got me scratching my head and I can't seem to get past it - can someone help?

 

Trying to access a JSON property dynamically but it tells me that the property that clearly exists doesn't. ???????

 

atmydeskscratch_0-1634322595633.png

 

 

 

Situation:

Trying to create a flow that is generic and uses an online spreadsheet to map fields. These fields are then used to help pull out values from a JSON object that has dynamic properties and values.

Sample JSON payload that I create and send to a handler flow:

{
 "formId": "somelongstingoflettersreferringtoaform", 
 "responder": "responder@abc.com", 
 "questions": [ 
 { 
 "id": "r78dbe3634ee567889a4c12be12345678", 
 "question_and_answer": { 
 "What do you need help with": "Something I can't figure out" 
 }
 } 
 ] 
}

Sample mapping values:

formId : somelongstingoflettersreferringtoaform
q_id : r78dbe3634ee567889a4c12be12345678 
question : What do you need help with 
field_type : Category

 

Steps in the flow

I use the filter array (f_arr_1) to retrieve the mapping values I need from the mapping spreadsheet:

#Filter array advanced mode:

@equals(item()?['field_type'], 'Category')

where Category refers to my mapping.

which returns:

# returned by f_arr_1 
[
 { 
 "@odata.etag": "", 
 "ItemInternalId": "0aaa00a0-aaa0-00a0-aaa0-00000de000aa", 
 "formId": "somelongstingoflettersreferringtoaform", 
 "question_hash": "r78dbe3634ee567889a4c12be12345678", 
 "question": "What do you need help with", 
 "field_type": "Category" 
 } 
]

Then I pass the questions array from the JSON payload accepted by the flow and use another filter array (f_arr_2) to select question_and_answer

#Filter array advanced mode:

@equals(item()?['id'], body('f_arr_1')[0]['q_id'])

# where q_id refers to my mapping and inserts r78dbe3634ee567889a4c12be12345678

which returns

# returned by f_arr_2
[
 { 
 "id": "r78dbe3634ee567889a4c12be12345678", 
 "question_and_answer": 
 { 
 "What do you need help with": "Something I can't figure out" 
 } 
 }
]

I assign

variables('question') = body('f_arr_2')[0]['question_and_answer']

so that variables('question') returns

{ 
 "What do you need help with": "Something I can't figure out" 
}

I also assign

variables('selectON') = body('f_arr_1')[0]['question']

so that variables('selectON') returns

What do you need help with

Problem:

The problem is when I try to dynamically access the property 'What do you need help with' from variables('question').

The expression I use is:

variables('question')[variables('selectON')]

The error is:

Unable to process template language expressions in action 'Initialize_variable' inputs at line '1' and column '16134': 'The template language expression 'variables('question')[variables('selectON')]' cannot be evaluated because property 'What do you need help with' doesn't exist, available properties are 'What do you need help with'. Please see https://aka.ms/logicexpressions for usage details.'.

Notice that the error message says

'What do you need help with' doesn't exist, available properties are 'What do you need help with'

HOWEVER....

When I specify the name of the property explicitly,

variables('question')['What do you need help with']

it resolves with no issue.

Only trouble is that I will have to hardcode the value. I do not want to do that....

Help please!!!
I have the same question (0)
  • tom_riha Profile Picture
    10,181 Most Valuable Professional on at
    Re: Issue accessing property of an object with a dynamic value

    Hello @atmydeskscratch ,

    did you try to build the logic using 'Compose' actions instead of variables (if possible in your use case)? I can imagine there might be some problem with the fixed variable types, which is not a problem when using 'Compose' or building the whole expression in a single step.

    body('f_arr_2')[0]['question_and_answer'][body('f_arr_1')[0]['question']]

     

  • atmydeskscratch Profile Picture
    2 on at
    Re: Issue accessing property of an object with a dynamic value

    Hi @tom_riha ,

     

    Thanks for taking some time to review my problem.

     

    I tried your suggestion just now but I get the same error.  In the meantime I 'solved' the problem in a very hacky way, so to say I'm not satisfied with my approach.  Nonetheless it works, but I'd love to get to the bottom of why I'm having trouble with what looks to me like valid code.

     

    here is my hack job:

     

    replace(replace(string(split(string(body('f_arr_2')[0]['question_and_answer']),':')[1]),'"',''),'}','')
    
    #
    # Cast Object to Sting, split it by the :, select the second token, replace all occurences of " with nothing, and replace the final instance of } with nothing.
    #
    
    { 
     "What do you need help with": "Something I can't figure out" 
    }

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Coming soon: forum hierarchy changes

In our never-ending quest to improve we are simplifying the forum hierarchy…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 535 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 348 Moderator

#3
developerAJ Profile Picture

developerAJ 262

Last 30 days Overall leaderboard