When working with Dynamics 365 you’ve probably come across the requirement to update related records based on a field of the parent record. Some business examples I’ve encountered are:
- Copy the address from an account to its contacts.
- Copy the primary contact on the account to its opportunities.
There’s tons of examples out there. I even blogged about a No-Code solution in Dynamics CRM back in 2017. For this mini-tutorial I will be using Flow to copy the website field from an account to its contacts.
Tutorial on updating related records
- Fire up your make.powerapps.com environment and create a new Flow.
- Add a new Trigger, When a record is created, updated or deleted. Be sure to use the Current Environment connector.
- Update the settings as follows:
- Trigger condition: Update
- The entity name: Accounts
- Scope: Organization
- Filtering attributes: websiteurl
Setting the filter attributes will ensure that the Flow triggers only when the website field is updated. Doing so, prevents the Flow from running needlessly.
- Add a new step and choose List Records. Again, pay attention to using the correct Connector, which is the Current Environment connector.
- In this step you’ll define which contacts need to be retrieved. Fill in the Flow as shown below.
- Entity name: Contacts
- Select Query: contactid
- Filter Query: _parentcustomerid_value eq ‘accountid_from_trigger’ and statecode eq 0
Now we’re not really interested in retrieving any information from the contact, so we can just put the contactid in the Select Query. The Filter Query is where we define which contacts should be retrieved, by definining the link with the account and adding a filter on status. Note that we’ve added the dynamic Account field from the previous step.
- Add another step. This time, choose Update a record.
- Select Contacts as Entity Name. In the Item ID field, enter the Contact field that is found under the List Records step. Doing so will automatically create a correct For-loop.
- Scroll down to the Website field. Select it and fill it with the Website field that you find in the Dynamic content pane.
- That’s it! You’re all set. Don’t forget to fill in a name for the Flow and save it.
Behold the end result
After creating this Flow, we simply go to Dynamics 365 Sales and update the website field on one of our accounts. After that, check out the contacts linked to the account and you should see the website url propagated. Of course this was a fixed example, but based on the above, you should be able to write any Flow to update related records.
In a follow-up post I will describe how to clear lookup fields using Flow, as the update mentioned below will not work for that particular scenario.
Did the above work for you? Let me know in the comments below!