0

How to get values from array with Composeaction?

I will try Azure Cognitive Service - Extract information from invoices. There is an Array called keyValuePairs.

How I can get to single values ?

  1. Initialize variable - varArray

  2. Set Variable keyValuePairs - output:

     [
     "@odata.type": "#Microsoft.Dynamics.CRM.expando",
     "key": "Number",
     "value": "20230002",
     "confidence": 0.907,
     "keyLocation": {
     "@odata.type": "#Microsoft.Dynamics.CRM.expando",
     "page": 1,
     "boundingBox": {
     "@odata.type": "#Microsoft.Dynamics.CRM.expando",
     "left": 0.5104732920061759,
     "top": 0.1300018790827594,
     "width": 0.11190841384289363,
     "height": 0.009177612878252667,
     "polygon": {
    

Compose action

variable('varArray')?['key']?['Number']?['value']

Error

Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template function 'variable' is not defined or not valid.'.

1
  • 1
    If you want to get value from first object in array, try: first(variables('varArray'))?['key'] for key and first(variables('varArray'))?['value'] for value. Let me know if it works. Feb 27, 2023 at 13:51

1 Answer 1

1

If you want to get value from first object in array output, use:

For key:

first(variables('varArray'))?['key']

For value:

first(variables('varArray'))?['value']

Or you can use Apply to each action with array output and inside loop, you can use expressions like:

For key:

item()?['key']

For value:

item()?['value']
5
  • What if i want exactly value from key number? And this value isn't first. My goal get return this ''''20230002''''
    – Novice
    Feb 27, 2023 at 14:46
  • Check 2nd approach in my answer > You can use Apply to each, user array as input to apply to each > Inside apply to each action, you can add compose action and use expression like: item()?['value'] Feb 27, 2023 at 14:55
  • Can you share example of data with multiple items in the array to understand the data and suggest better expression? Feb 27, 2023 at 14:56
  • Yea apply to each, but i no need all keys just one key with name number, can be item?('key'=='number') assign like this?
    – Novice
    Feb 27, 2023 at 15:07
  • 1
    Inside Apply to each > Add "Condition" > use condition like: item()?['key'] is equal to Number > Then inside "If yes" block of condition, use compose action as mentioned above. Feb 27, 2023 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.