{"id":108,"date":"2022-01-04T11:17:35","date_gmt":"2022-01-04T11:17:35","guid":{"rendered":"https:\/\/blog.citrus-lime.com\/crmc\/?p=108"},"modified":"2022-01-04T11:17:35","modified_gmt":"2022-01-04T11:17:35","slug":"creating-a-flow-to-add-a-many-to-many-relationship","status":"publish","type":"post","link":"https:\/\/blog.citrus-lime.com\/crmc\/creating-a-flow-to-add-a-many-to-many-relationship\/","title":{"rendered":"Creating a Flow to add a Many-to-Many Relationship"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_626BA691.png\"><img decoding=\"async\" src=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_thumb_3DDA190D.png\" alt=\"image\" title=\"image\" \/><\/a><\/figure>\n\n\n\n<p>In my case, I am looking to trigger when a new Quote is created in CRM.<\/p>\n\n\n\n<p>From there, I want a List Records Action to define what other records that I am seeking to associate to my Quote \u2013 in my case, a Custom Entity titled \u2018Other Costs\u2019.<\/p>\n\n\n\n<p>We don\u2019t want all the Other Cost records, only a subset tagged as \u2018automatically create with Quote\u2019 \u2013 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.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_169FCFD8.png\"><img decoding=\"async\" src=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_thumb_643BFC58.png\" alt=\"image\" title=\"image\" \/><\/a><\/figure>\n\n\n\n<p>With my Flow\u2019s input established, I can then add the action I want to run as the Flow\u2019s Business Logic \/ Output \u2013 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.<\/p>\n\n\n\n<p>This is where we need to use the Relate Records Action and it does have a bit of quirkiness to overcome.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_78C14BD6.png\"><img decoding=\"async\" src=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_thumb_4D7CB4CF.png\" alt=\"image\" title=\"image\" \/><\/a><\/figure>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Here we need to supply a piece of syntax that points Flow to the Entity\u2019s reference in the Dynamics REST API, this delves into mild development territory and so is a bit weird, but we can map this out:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>https:\/\/mycrm.crm.dynamics.com\/api\/data\/v9.0\/<strong>&lt;entity-db-name&gt;<\/strong>(ID)<\/p><\/blockquote>\n\n\n\n<p>So for my notation:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_542FBE52.png\"><img decoding=\"async\" src=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_thumb_660C521F.png\" alt=\"image\" title=\"image\" \/><\/a><\/figure>\n\n\n\n<p>This then specifies the Quote to link to the Other Costs record.<\/p>\n\n\n\n<p>With this built, my Flow is done and so its onto Testing.<\/p>\n\n\n\n<p>To start with, I need to manually trigger the Event in Dynamics that will start my Flow \u2013 in my case, creating a new Quote:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_01B0DE16.png\"><img decoding=\"async\" src=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_thumb_6F681753.png\" alt=\"image\" title=\"image\" \/><\/a><\/figure>\n\n\n\n<p>I then dive back into Flow to see how the execution went from this manual trigger:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_2408738F.png\"><img decoding=\"async\" src=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_thumb_7CCE2A59.png\" alt=\"image\" title=\"image\" \/><\/a><\/figure>\n\n\n\n<p>This then helps define my new Quote:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_1872B650.png\"><img decoding=\"async\" src=\"https:\/\/license.citruslime.com\/cs\/blogs\/crmcs\/image_thumb_434B1A62.png\" alt=\"image\" title=\"image\" \/><\/a><\/figure>\n\n\n\n<p>And so we have a new piece of logic to automatically add 1 or more associations for each Quote we add to Dynamics 365.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">More Reading on Power Automate<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>This is a great article for help when using the Relate Records Action &#8211;&nbsp;<\/strong><a href=\"https:\/\/tattooedcrmgirl.com\/2019\/10\/30\/microsoft-flow-the-relate-records-action-demystified\/\"><strong>https:\/\/tattooedcrmgirl.com\/2019\/10\/30\/microsoft-flow-the-relate-records-action-demystified\/<\/strong><\/a><\/p><p><strong>CRMCS Post to help with the List Records Action &#8211;&nbsp;<\/strong><a href=\"https:\/\/www.crmcs.co.uk\/content\/building-and-testing-a-flow-for-dynamics.aspx\"><strong>https:\/\/www.crmcs.co.uk\/content\/building-and-testing-a-flow-for-dynamics.aspx<\/strong><\/a><strong>&nbsp;<\/strong><\/p><p><strong>Microsoft Documentation on the Common Data Service (current environment) &#8211;&nbsp;<\/strong><a href=\"https:\/\/docs.microsoft.com\/en-us\/connectors\/commondataserviceforapps\/\"><strong>https:\/\/docs.microsoft.com\/en-us\/connectors\/commondataserviceforapps\/<\/strong><\/a><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>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<\/p>\n","protected":false},"author":43,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_price":"","_stock":"","_tribe_ticket_header":"","_tribe_default_ticket_provider":"","_tribe_ticket_capacity":"0","_ticket_start_date":"","_ticket_end_date":"","_tribe_ticket_show_description":"","_tribe_ticket_show_not_going":false,"_tribe_ticket_use_global_stock":"","_tribe_ticket_global_stock_level":"","_global_stock_mode":"","_global_stock_cap":"","_tribe_rsvp_for_event":"","_tribe_ticket_going_count":"","_tribe_ticket_not_going_count":"","_tribe_tickets_list":"[]","_tribe_ticket_has_attendee_info_fields":false,"footnotes":""},"categories":[3],"tags":[],"class_list":{"0":"post-108","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-crm"},"featured_image_src":null,"author_info":{"display_name":"jadesmith","author_link":"https:\/\/blog.citrus-lime.com\/crmc\/author\/jadesmith\/"},"_links":{"self":[{"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/users\/43"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":1,"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":109,"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/posts\/108\/revisions\/109"}],"wp:attachment":[{"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.citrus-lime.com\/crmc\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}