When reviewing one of our Dynamics Prototyping Projects, we identified a Requirement where we wanted a new Many-to-Many (N:N) link to be created immediately as a new Quote was recorded.

Typically creating a new Many-to-Many link could be difficult in traditional Dynamics Workflow, and so thought this would be a good worked example for how we can use Power Automate (nee Flow) to implement this requirement.

So, getting started, we kick off by adding a New Flow to our Dynamics 365 Solution and defining a Trigger for the Common Data Service (current environment) for when a record is created, updated or deleted.

image

In my case, I am looking to trigger when a new Quote is created in CRM.

From there, I want a List Records Action to define what other records that I am seeking to associate to my Quote – in my case, a Custom Entity titled ‘Other Costs’.

We don’t want all the Other Cost records, only a subset tagged as ‘automatically create with Quote’ – so I can jump into a Dynamics Advanced Find and produce a block of Fetch XML that returns me the right set, and then feed this Fetch XML into the List Records step.

image

With my Flow’s input established, I can then add the action I want to run as the Flow’s Business Logic / Output – in this case, looping through each of the returned records and adding the association that would link the New Quote to the returned Other Cost record.

This is where we need to use the Relate Records Action and it does have a bit of quirkiness to overcome.

image

Afterwhich we supply the ID of our Other Costs record, select the N:N Relationship we want to associate and then come to which Quote we want to associate to.

Here we need to supply a piece of syntax that points Flow to the Entity’s reference in the Dynamics REST API, this delves into mild development territory and so is a bit weird, but we can map this out:

https://mycrm.crm.dynamics.com/api/data/v9.0/<entity-db-name>(ID)

So for my notation:

image

This then specifies the Quote to link to the Other Costs record.

With this built, my Flow is done and so its onto Testing.

To start with, I need to manually trigger the Event in Dynamics that will start my Flow – in my case, creating a new Quote:

image

I then dive back into Flow to see how the execution went from this manual trigger:

image

This then helps define my new Quote:

image

And so we have a new piece of logic to automatically add 1 or more associations for each Quote we add to Dynamics 365.

Historically this would require a quick Custom Workflow Activity or a Post-Update Plugin, but here we can realise the same requirement with a Low Code approach.

More Reading on Power Automate

This is a great article for help when using the Relate Records Action – https://tattooedcrmgirl.com/2019/10/30/microsoft-flow-the-relate-records-action-demystified/

CRMCS Post to help with the List Records Action – https://www.crmcs.co.uk/content/building-and-testing-a-flow-for-dynamics.aspx 

Microsoft Documentation on the Common Data Service (current environment) – https://docs.microsoft.com/en-us/connectors/commondataserviceforapps/

Author

Write A Comment