Support Portal ContactGet in touch

Creating a Flow to add a Many-to-Many Relationship

   Words by Paul McQuillan

   on 28/04/2020 08:00:00

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/

  • "Paul has made a real difference to how my team of 24 people record and store valuable customer data and sales opportunities. Highly recommended."

    James, Operations Director

  • "Understanding your business allows us to advise when to implement aspects of CRM and, likewise, when not to."

    Paul McQuillan, Managing Director

  • "Dynamics 365 and CRMCS have made a real lasting difference to our business, allowing us to replace older systems that were holding back our performance."

    Grahame, Chief Operating Officer

  • "James worked well with us to help connect CRM with Outlook and relate how this might benefit our team using CRM for Property Care."

    Natalie, Property Care Supervisor

  • "Matt was really good with helping us run User Testing on the new Compliance Module of our CRM System."

    Tom, Compliance Administrator

Prefer to go old-school?

Write to us using the below addresses.

Head Office
CRM Consultancy
61 Oxford Street
Manchester
M1 6EQ

London Office
CRM Consultancy London
Grosvenor Avenue
London

Content © CRM Consultancy.