Filter Dynamics 365 data by lookup in Azure Logic Apps

I have been playing with logic apps in Azure to see if I could solve a business problem in a more robust, quicker and reliable manner than the usual integration options.

When using the the Dynamics 'List Records' function, you have the option to add a filter to the query to allow you to be specific on the exact record(s) you want returned. What wasn't obvious was how to apply a filter based on a lookup field on an entity.

alt

The current Dynamics 365 documentation's doesnt provide an example or guideline on this but after looking under the hood & analysis, the correct way to reference a lookup field in a filter is in the format "_schemaname_value" e.g the standard "primarycontactid" field on the account entity would be referenced as "_primarycontactid_value" . The query would then look along these lines

alt You could now for example find opportunities related to a specific account, iterate over each of those records and use that information in other areas within your logic app. Hope that saved you some time!