Associate / Disassociate two entities with 1: N and N: N relationship using Relate & Unrelate records in Power Automate

Sending
User Review
0 (0 votes)

Introduction

Power Automate has been introducing new features and one of them is ‘Relate/Unrelate Records’ feature. This is a step towards new common data service connector and it supports 1: N, N: N relationships. Now, let’s see with an example how it works. We have two entities ‘Contact’ and ‘Web Role’ and there is N: N relationship between them.
Our flow will run on the creation of contact and for that contact we will set default web role as authenticated users.
Here, we first initialize a variable and set the default role name in it.

Associate and disassociate two entities

Now, fetch the web role using the web role name.

Associate and disassociate two entities

We also need to initialize one more variable to store the @odata.id of the web role which is actually a full resource URL of web role e.g. https://organizationName.crm8.dynamics.com/api/data/v9.0/adx_webroles(844598bc-d0cb-410a-b2de-b6f2c4dbc487)

(CDS connector dynamically provides it along with the record details.)

Associate and disassociate two entities

In the next step set the value of our role id variable.

Associate and disassociate two entities

Here, you will see we are setting up only one web role in the contact record and that is the reason we are using the variable to initialize and set it by the web role id in the apply to each loop, but we could have the requirement to set more than one web role in the contact so at that time we must place the related records step inside the apply to each loop instead of setting up variable.

Now at last set the Relate Records step where one needs to set some properties as listed below.

The properties you are required to fill are as follows:

  • Entity Name: – Select the entity that has N: N, 1: N relationship with associate entity, in our case the contact.
  • Item Id: – Record id.
  • Relationship: – Select the relationship.
  • URL:- Full address of the associated entity record, which we have stored in the role id variable.

Associate and disassociate two entities

Please note if you want to remove the relationship then you can use Unrelate Records step and that also require same properties as Relate records step.

Result: – Please check below screenshot when we created a contact in CRM and flow got triggered respectively.

Associate and disassociate two entities

Associate and disassociate two entities

Conclusion

So, this is how using relate and unrelate records step we can associate or disassociate two entities, which has 1: N or N: N relationship between them.

Leave a Reply