Associate and Disassociate records in Power Apps Canvas Apps

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

With every new release of Canvas apps, Microsoft add new features to it’s kitty. Today I will explain one of these features. And that is the ability to associate records in Canvas apps. I am going to walk you through on how we can associate and disassociate entity records in 1:N and N:N relationship.

One to Many

For this demo I have built a small canvas application. The application shows both the Accounts and Contacts list.

Relate records in Canvas apps

When the “Associate” button is clicked, it will associate a contact to the account record. And we can do this using the Relate() function in canvas apps.

In “OnSelect” event of the associate button, I use the below formula.

Relate formula canvas apps
BrosweGallery 1 – Accounts. Gallery1 – Contacts

It’s pretty easy I guess to understand what the function does. I take the selected item from Account gallery and then specify the relationship name. The second parameter of the function take the child record. Hence I have used the selected contact from Contacts Gallery in the second parameter.

When I click the Associate button, magic happen. The contact record is now associated with the account.

Similarly to disassociate, we need to use the Unrelate() method. The Unrelate function has a similar nomenclature like the Relate function. Below is the formula to disassociate contact from the account record.

Unrelate function in Canvas Apps

Many to Many

The syntax for many to many relationship is actually the same as one to many. The only difference is with many to many, we can use the Relate function and Unrelate function with both the participating entities. So for an account and contact in N:N relationship, to associate a contact with the account, I use the below code.

Relate(<AccountRecord>.'Contacts', <ContactRecord>)

Similarly to associate an account with the contact, I use the below code

Relate(<ContactRecord>.Accounts, <AccountRecord>)

Hope this helps!

Debajit Dutta

Debajit Dutta

Solutions Architect

XrmForYou Consulting Private Limited

Email : info@xrmforyou.com