We can Associate or disassociate two entity record with N:N or 1: N relationship using Power Automate
Connector to use: common data service (current environment)
Action to use: Relate Records
We would be using Contact and campaign N:N Custom Relationship when Contact is created get source campaign from lead and map with contact.
- Create new Automated Flow
- Name the Flow and Choose Trigger, in our case its creation of record contact
- Get Lead Record Item Unique id as Lead Source, To get source Campaign ID
- Now We have Source Campaign ID from Lead and Contact Id, But to use relate Action we need OData URL for a related entity that is Campaign
https://organizationName.crm8.dynamics.com/api/data/v9.0/campaigns(0d8dda4c-126e-e911-a980-000d3ae4c063)
Where GUID will be mapped with Dynamics field value campaign ID - Selecting Action Relate record this action, Select Primary Entity i.e contact, Map Contact unique id, Relationship Name, URL
Save and Turn On the flow. Now each time contact is created and source lead contains campaign both will be associated using relate action.
Unrelate Action can be used to Disassociate the record same way.