Loop through array of objects in a Flow & Create records in CDS | Power Automate

One of the most common scenarios that are looked out for are ways to loop through an array of objects received (say, from HTTP response) and create CDS records

Sample Data

Let’s say this is the sample data coming in which is an array of objects. This is coming from my HTTP trigger which I created and hosted. It could be anything else in your case
undefined

And the body looks something like this –

[{"Name":"FreshBeans Coffee","City":"Mumbai","Phone":999999999},{"Name":"Timber Mart","City":"Pune","Phone":999999999}]

Generate Schema from Payload

I need to first create the Schema to be able to easily read from the JSON response
undefined

Paste a sample Payload in the dialog box
undefined

And it will generate a Schema
undefined

And when this is generated, you can access the attributes further in your Flow
undefined

What if you just enter a blank object and not generate from Schema or enter Schema explicitly as shown below –
undefined
You won’t get the attributes from the JSON Payload which is needed further
undefined

Loop through array and Create in CDS

Now, you can use Apply To Each and pass the Parsed JSON Body. I’ve simply used Compose to see the entire Object while checking results (No other purpose of using Compose in this example)
undefined

And then the next step is to Create CDS records from the looped Objects. So, since I have the schema generated above, I can use the attributes to directly map it to the CDS Create Record action

undefined

Running the Flow

Finally, once I run the Flow and check the actions performed. I’ll create 2 records since there are 2 objects in my array.

I’ll see the Compose step to see what I got in the object. As I mentioned earlier, this is not required- I just intend to put it there to see what data came in
undefined

And the Create Record in CDS step will create record in my Dynamics 365 environment as I intended it to do –
undefined

I can check the same in Dynamics 365
undefined

You might also want to check other posts related to Power Automate –

  1. Get Count of records retrieved in CDS connector in a Flow | Power Automate
  2. Number Formatting in a Flow | Power Automate
  3. Call a Dynamics 365 Action from Flow [Bound and Unbound Actions] | Power Automate
  4. Switch-Case in a Flow | Power Automate
  5. Setting Retry Policy for an HTTP request in a Flow | Power Automate
  6. Make HTTP request from Flow in Power Automate
  7. Button Flow in Power Automate to replicate a Quick Create Form in D365 CE
  8. Enable Flow button on D365 Ribbon

Hope this was easy!

Advertisement