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
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
Paste a sample Payload in the dialog box
And it will generate a Schema
And when this is generated, you can access the attributes further in your Flow
What if you just enter a blank object and not generate from Schema or enter Schema explicitly as shown below –
You won’t get the attributes from the JSON Payload which is needed further
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)
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
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
And the Create Record in CDS step will create record in my Dynamics 365 environment as I intended it to do –
I can check the same in Dynamics 365
You might also want to check other posts related to Power Automate –
- Get Count of records retrieved in CDS connector in a Flow | Power Automate
- Number Formatting in a Flow | Power Automate
- Call a Dynamics 365 Action from Flow [Bound and Unbound Actions] | Power Automate
- Switch-Case in a Flow | Power Automate
- Setting Retry Policy for an HTTP request in a Flow | Power Automate
- Make HTTP request from Flow in Power Automate
- Button Flow in Power Automate to replicate a Quick Create Form in D365 CE
- Enable Flow button on D365 Ribbon
Hope this was easy!