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 IV
Helper IV

@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 IV
Helper IV

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
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MSFTBizAppsLaunchEvent

Experience what’s next for Power Virtual Agents

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (45,716)