cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
virakones
Resolver II
Resolver II

How to Select value from Object using value from array as the Key?

Hello,

 

I have an Adaptive Card that returns to me a submitted response that includes all dynamic responses in a single object.

 

Those dynamic inputs have an id assigned - this id is the key containing the value I want assigned to it.

 

 

{
    "body": {
        "5caf4a2f-b16b-eb11-a812-000d3a987ca7": "Value1",
        "fc02e508-b26b-eb11-a812-000d3a987ca7": "Value2"
    }
}

 

 


I have a separate array to compare the object against:

 

 

{
  "ids": [
    {
      "id": "5caf4a2f-b16b-eb11-a812-000d3a987ca7"
    },
    {
      "id": "fc02e508-b26b-eb11-a812-000d3a987ca7"
    }
  ]
}

 

 


In the end, I want to be able to transform the data to below:

 

 

{
  "data": [
    {
      "id": "5caf4a2f-b16b-eb11-a812-000d3a987ca7",
      "value": "Value1"
    },
    {
      "id": "fc02e508-b26b-eb11-a812-000d3a987ca7",
      "value": "Value2"
    }
  ]
}

 

 


Question: How would I be able to iterate through the values from the array of id's and select the values from an object using those ids as the key?

1 ACCEPTED SOLUTION

Accepted Solutions
v-yiwenxie-msft
Microsoft
Microsoft

Hi @virakones 

 

The following flow is for your reference:

2.15-4.PNG

 

The inputs for all the ‘compose’ actions are:

 

Compose:

{

  "ids": [

    {

      "id": "5caf4a2f-b16b-eb11-a812-000d3a987ca7"

    },

    {

      "id": "fc02e508-b26b-eb11-a812-000d3a987ca7"

    }

  ]

}

 

Compose 3:

outputs('Compose')?['ids']

 

Compose 2:

{

  "body": {

    "5caf4a2f-b16b-eb11-a812-000d3a987ca7": "Value1",

    "fc02e508-b26b-eb11-a812-000d3a987ca7": "Value2"

  }

}

 

Compose 5:

outputs('Compose_2')?['body']

 

Compose 4:

outputs('Compose_5')[items('Apply_to_each')?['id']]

 

Compose 6:

{

"id": "@{items('Apply_to_each')?['id']}",

"value": @{outputs('Compose_4')}

}

 

Best Regards,
Community Support Team _ Kira Xie
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yiwenxie-msft
Microsoft
Microsoft

Hi @virakones 

 

The following flow is for your reference:

2.15-4.PNG

 

The inputs for all the ‘compose’ actions are:

 

Compose:

{

  "ids": [

    {

      "id": "5caf4a2f-b16b-eb11-a812-000d3a987ca7"

    },

    {

      "id": "fc02e508-b26b-eb11-a812-000d3a987ca7"

    }

  ]

}

 

Compose 3:

outputs('Compose')?['ids']

 

Compose 2:

{

  "body": {

    "5caf4a2f-b16b-eb11-a812-000d3a987ca7": "Value1",

    "fc02e508-b26b-eb11-a812-000d3a987ca7": "Value2"

  }

}

 

Compose 5:

outputs('Compose_2')?['body']

 

Compose 4:

outputs('Compose_5')[items('Apply_to_each')?['id']]

 

Compose 6:

{

"id": "@{items('Apply_to_each')?['id']}",

"value": @{outputs('Compose_4')}

}

 

Best Regards,
Community Support Team _ Kira Xie
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

@v-yiwenxie-msft 

Thank you! This has been bugging me for a while. I appreciate the help - there is no way I would have considered using those compose actions the way you outlined but the end result is fantastic. 

NielsL
Helper V
Helper V

@virakones thank you for pointing me in the direction of this thread. This is exactly what I am looking for. 

 

Can you share with me, how you created the separate array with the IDs to compare against?

NielsL
Helper V
Helper V

Nevermind, I got it working. I always thought it would be possible somehow, but I would never have come up with that solution myself. 

 

Thanks both of you, @virakones @v-yiwenxie-msft 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (2,860)