Understanding the Expand Query in the Dynamics 365 List Records connector – Part 2

Hello;

Part one of this post (Understanding the Expand Query in the Dynamics 365 List Records connector) showed how to utilize the expand query paramete. This post will covering actually using these values to update an account with the data. Let’s dive right into part two of using the expand query in the Dynamics 365 connector that is used in Power Apps, Logic Apps, and Flow.

We left off with our related primarycontactid data returned from our account request.
Dynamics 365 - List Records

Since we have our data the next thing is to take action on these returned records. We’re going to add an Apply to each  as the next step. We’ll add the value from dynamic content. This will be each record returned from the Account Query. We will want to choose an action. In this case we’re going to use the Data Operations – Parse JSON. Let’s go ahead and select this action.
Apply to Each

The Parse JSON action allows us to specify which returned field to parse on. This is an important step to get correct. Using the Dynamic Content you can search and select the Primary Contact item. The next step is critical; hovering over it to ensure it has the right field name(see expand query field for the proper name); in our case it’s “primarycontactid”. This is critical step as its very easy to get the wrong field here.
Parse JSON

Using the Parse JSON it’s required to enter the schema; luckily it allows us to paste data and it’ll generate this for us. In this case I’ve simply used the data returned for my account from the previous post.

Parse JSON
The generated schema comes out like the following.

{
    "type": "object",
    "properties": {
        "@@odata.type": {
            "type": "string"
        },
        "fullname": {
            "type": "string"
        },
        "firstname": {
            "type": "string"
        },
        "lastname": {
            "type": "string"
        }
    }
}

Now that the schema is completed; we’re now able to use this transformed data dynamically. We’re going to update the account name to include the contact full name. Adding a Dynamics 365 – Update record action is the first step. When clicking into any field you can now see the dynamic data of both the Parse JSON result and List Records(Previous) aka the account data.
Dynamics 365 - Update Record

The flow is now completed. Let’s execute this and double check within CRM to see if it updated properly. We can see the results of the update step.
Successful Execution

After double checking CRM to see our record updated I think we can call this a wrap.
Account

We’ve went through parsing the expanded query results and turning them into Dynamic Content to be used. There are a ton of other things that can be done with the different actions and conditions; but this is a basic example of how to use the Expand Query field in the connectors.

I hope you’ve found this helpful.!