Understanding the Expand Query in the Dynamics 365 List Records connector

Hello;

Recently I’ve been diving deeply into the Dynamics 365 connector that is used in Power Apps, Logic Apps, and Flow. I’ve found the documentation lacking when trying to do more advanced features. Today were discussing the Expand Query component of this connector.

First lets start with a new flow and add the Dynamics 365 – List Records(preview) connector.
Dynamics 365 - List Records

Once we have the connector added we’re going to retrieve all Accounts. We select an organization and then select which entity we’re going to use. This will get us all accounts in the organization.
Dynamics 365 - List Records

The Expand Query option is where we’re going to focus on. MSDN documents this field here.  The documentation states:

Expand Query
string
Related entries to include with requested entries (default = none)
Key:
$expand

This doesn’t really give us a practical example to work from. When researching online the majority of searches come back with using the relationship name of a relationship. This is actually incorrect. Let’s take the Primary Contact relationship on the Account entity as an example.
Dynamics 365 - List Records

For the Expand Query field it actually takes the lookup value of this relationship. In this case it is looking for the “primarycontactid”.

Let’s go back to our query and add this in.
Dynamics 365 - List Records

As you can see we’re able to specify the lookup field and then select exactly which columns to be retrieved from the Contact entity. The output of this query returns the related record in a json object.

      "primarycontactid": {
        "@odata.type""#Microsoft.Azure.Connectors.Crm.SubItem",
        "fullname""Jason Cosman",
        "firstname""Jason",
        "lastname""Cosman"
      }

Getting the related record is only half the battle as it isn’t able to be used as dynamic content yet. You have to parse it out and then use it. Stay tuned for the next post where we update the account with contact information using the retrieved data.