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

By | February 24, 2020

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.

70% of global 2000 companies apply gamification to improve productivity and returns!

Gamifics365 – Spin the magic of games within Microsoft Dynamics 365 CRM to improve user adoption, enhance productivity, and achieve company goals!

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

  1. Coolie

    Hi fantastic article – its just what I was looking for to relate (new) contacts to the Account. However its now MS DataVerse and things have changed a little. The problem I am having is: a new contact is created (on a schedule from external Web API), but I cant associate this with the Account, because Flow is expecting the Account ‘Row ID’ instead of ‘Item ID’, and which it says must be a GUID. I only have the customer id in the contact so I am stuck trying to get the record to appear in the subgrid of the Account form. Ive trawled the Web but cant find any up-to-date examples. Could you help with this please?

    1. Inogic

      It seems your customer id is unique identity of your account which is present in your CRM.
      And by using customer id you want to find the appropriate account and set the lookup of that account into your newly created contact. So if our understanding is correct then your Power Automate Flow should be running on the creation of contact and then you will have the contact id in a flow.
      So using that customer id you can search for account and use the account id in the related step.
      And if your flow isn’t executing on the creation or update of the contact then please explain us more about your scenario.

      Thanks!

Comments are closed.