Microsoft Flow has definitely leveraged the capabilities of Dynamics 365 to a next level and with the long list of connectors, it provides seamless integration across various different digital ecosystems.
In this blog we are going to discuss a workaround to retrieve records linked to each other via many to many relationship in Dynamics 365.
Currently, flow provides the capability to retrieve records linked to each other via One to Many relationship by using expand property but when we used the expand property to retrieve records linked to each other via Many to Many relationship, it didn’t provided the expected response. As a workaround we have to pull the records via a link entity (An intermediate entity that holds record of relationship between two different entities).
For our reference we would take the example of Marketing list and Contact records as they are linked to each other via Many to Many (N:N) relationship. We would perform some operation on list related contact records.
Following are the steps to achieve the above described objective:
In the above image you can see that we have used the link entity named “listmembers” which holds the link between contacts and marketing list, this listmembers entity is not available by default but you can access it by selecting Enter custom value from the Entity Name dropdown and then write it manually in the Entity Name text field.
In order to filter the relevant records we have used a filter query that makes sure that only rows that contain link between the list and contact with the provided guid are retrieved and nothing else should be retrieved so we have used _listid_value eq <guid>.
Once we get the list of link entity records then we will use an apply to each to retrieve contacts from Dynamics CRM one by one and we can perform any further operation after the retrieve contact records(list record step).
- Listmembers – It is the name of our link entity(may differ depending on your related entities)
- _listid_value – It represents listid of Marketing list in link entity record
- Entity(field name) – It represents contactid in link entity record
Note: The guid of the _list_value may differ as per your requirement. Also the unique identifier for the contactid is a parameter named Entity from the retrieved list which may also differ depending on the link entity.
Using above steps user can retrieve records linked to each other via many to many relationship in Dynamics 365 using Microsoft Flow.