cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
NielsL
Helper V
Helper V

Create records for each ID from output of an adaptive card (JSON)

I have a flow that posts an adaptive card to users in Teams. The adaptive card is dynamically populated with input toggles (checkboxes) based on records in Dataverse/CDS. So it will vary how many checkboxes there are for each adaptive card. 

For each of these input toggles/checkboxes, I would like to create a new record in Dataverse/CDS.

 

So my question is:

How can I extract/split/isolate each of these input toggles/checkboxes and use them in an Apply to Each loop in Power Automate? 

 

I have been looking at the substring action to see if that could be used. However, I haven't found a solution.


Adaptive card in Teams:

Adaptive card in TeamsAdaptive card in Teams

 

Output of the adaptive card in Power Automate:

NielsL_0-1607069096105.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
NielsL
Helper V
Helper V

I found a solution in another thread posted by @v-yiwenxie-msft. It might not be the most elegant solution, but it does the job. 

 

Solved: Re: How to Select value from Object using value fr... - Power Platform Community (microsoft....

View solution in original post

9 REPLIES 9

@NielsL 

I can't totally recreate this, but here's my theoretical idea:

  • Turn the "data" section into an Array using a Compose action and Split() to convert that string into an Array at the comma.
  • Filter the array where the value is "True" to only get the checked fields.
  • Use the output of that filter for your Create a Record" step, which should automatically trigger an Apply to Each loop.
  • Do the rest of the thing.

What do you think?

Either way, keep us posted.

-Ed

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

@edgonzales Thanks for the input. I think I need a bit more guidance to follow the steps you have outlined. However, it might make sense for me to adjust my current flow a bit.

 

I was toying around with the idea to create the records from the checkboxes earlier in the flow, as it then might be easier to update them. However, the issue for me is still to isolate them and run an Apply to each. And from an API Call perspective, it should make more sense to just create the records later in the flow - instead of creating the records early in the flow and then later updating the records.

 

Here's how the flow looks right now. The part highlighted is where the each of the new records are currently created (those records I initially tried to create from the JSON - but the issue remains the same). 

 

I am using a string variable to update the adaptive card with the input toggles. Maybe I can use an array from the start?

 

NielsL_0-1607329204280.png

 

 

 

 

 

 

 

 

 

 

@NielsL 

Possibly.  What does the output from the variable look like outside of the loop?

Oh, I forgot to expand that part of the screenshot. 

 

It will append the string variable with the a input toggle/checkbox for each record it loops through in the apply to each step:

{
            "type": "Input.Toggle",
            "title": "@{items('Apply_to_each_opportunity')?['name']}",
            "id": "@{items('Apply_to_each_opportunity')?['opportunityid']}"
        },

 

 

NielsL
Helper V
Helper V

@edgonzales 

 

I think I'm getting a bit closer. 

 

Using the expression below, I was able to extract the "data" section of the Parse JSON action and split it. 

 

split(string(body('Parse_Adaptive_Card_JSON')?['data']),',')

 

I'm not sure if I'm doing this right. However, I used the string function to convert the "data" part of the Parse JSON step from an object to a string to be able to use the split function - otherwise I got an error. That gives me the result below: 

 

NielsL_0-1607416277349.png

 

So the next step is to filter the above array (if it is an array at this point) and then create a record for each of these.

 

However, I'm stuck here. Do I need to use the either the  array or createArray functions here and then use the Filter Array step? 

@NielsL 

Awesome!  Great job!  This is exactly what I was talking about.  So, notice the square brackets on either side of the output of your last Compose?  That indicates that the information is already an Array.  The extra squiggle brackets ( "{" ) throw me off, but let's see what happens when you treat the output of that compose as the input of an Apply to each loop, to add the data to CDS.  

 

We may need to add in some key/titles, but at least now we have something to work with.

Good job!

-Ed

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

@edgonzales 

 

I can use the output of the compose action in an Apply for Each loop. So far so good.

 

However, as you mention, we need to somehow add some keys/titles to be able separate the GUID and the TRUE/FALSE to be able to use those as dynamic values to create the new records. 

 

I've been franticly googling to try and find out how to do that, but so far I've not come far. 

 

 

 

 

I'm just giving this a small bump. 

 

Does anyone know, if it is possible to convert the highlighted part of the output of the adaptive card to an array?

 

NielsL_3-1612859792856.png

 

So that the highlighed part looks like this instead:

 

[
  {
     "GUID": "95cd7081-886d-e911-a835-000d3ab865ed",
     "Status": True
  },
  {
     "GUID": "f99126a9-6913-eb11-a813-000d3ab39307",
     "Status": False
  },
    {
     "GUID": "b6752e08-7b60-eb11-a812-000d3adbb3c7",
     "Status": False
  }
]

 

I've been messing around with the data data operations actions. However, I have not been able to find a solution. 

NielsL
Helper V
Helper V

I found a solution in another thread posted by @v-yiwenxie-msft. It might not be the most elegant solution, but it does the job. 

 

Solved: Re: How to Select value from Object using value fr... - Power Platform Community (microsoft....

View solution in original post

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 (1,953)