In this post I will provide instructions how you can copy N-N related records using latest release of Ultimate Workflow Toolkit without any code.
Let’s consider typical scenario – qualification of Lead. Both Lead and Account have N-N relationship with entity Industry. When user wants to qualify Lead – Industries that are related to it have to be copied into Account that is created during qualification. Here is how it can be done:
Create “Industry” related action:
Add “Entity Reference” input with “Account” as a target entity:
After that add “UWT: N-N Operations: Associate Entities” step from Ultimate Workflow Toolkit:
and configure it:
set “Record 1 Reference” to “Url” for Industry, “Record 2 Reference” to “Url” for Account and “Relationship Name” to name of relationship between “Account” and “Industry” (uwt_industry_account) in my case.
Activate Action and close it.
Create “Account” workflow that should be executed on its “Create” event:
As a first step add a check that Account was created from Lead – “Originating Lead” has to contain value and if it does not – just stop the workflow execution:
With the next step start the preparation of special “Request” object that will be used in further steps – add a “UWT: Request Builder: Set Lookup Field” step to workflow:
and then configure it:
where “Field Value” is a reference to your account, “Field Name” – name you give to “Account” Input from Action you created on step 1. Leave “Request” field blank – it is used when you have multi-step population of fields of “Request” object.
The next step is to add “UWT: Bulk Operations: Distribute Action” step to workflow:
Here is how you need to configure it:
Set “Request” to “Modified Request” output of “Set Lookup field” step, populate “Action Name” with “Unique Name” of Action you created in a first part, pass “Url” of “Originating Lead” field of current account and set “Relationship Name” to uwt_industry_lead (this is the name between Industry and Lead in my case). Save and Activate your workflow.
So that’s it – let’s check it in action:
Hi Andrew, would I be able to copy the Opportunity Products from one Opportunity to a new opportunity using this process as part of a workflow?
The scenario I am struggling with is that we create a new opportunity from an existing opportunity on close of the first opportunity for the subsequent years renewal and I want this new opportunity to contain the same opportunity products as the original oppportunity that I am copying?
Hello Simon,
Approach will be similar to one that is provided in this post with the exception that you will have to use Opportunity -> Add Detail instead of Associate N-N records.
Feel free to get in touch if you have any issues.
Andrew
Thanks Andrew. I’ve had a go at setting this up but the opportunity products are not being copied across. I think it’s to do with the Action not firing as the workflow shows the usual green ticks against each line item, but the Action does not have any process Sessions logged.
Can I message you the screenshot of my action setup please? Not sure how to post it here…
Simon,
You can save screenshots somewhere online and leave references here.
Andrew
Hi Andrew,
Can I use the UWT to copy many-2-many records to a one-to-many entity. My scenario is the following:
1. User selects multiple countries (via the a default N-N multi-select form that comes when creating a N-N relation)
2. User selects a default marketing status and marketing status date
3. For each selected country (in step 1), I want to create a new record in a 1-N entity and copy the selected country and the default status/date .
Both the N-N relation and 1-N child-entity are associate to the same parent entity: product
Can the UWT handle this and how would I which tools should I use and in which order?
Best regards, Geron
Geron,
Your scenario is a bit complex for workflows with workflow packs. I would recommend to use custom code for it.
Thanks,
Andrew
Hi Andrew,
I got above scenario working using the DistributeAction. Works perfectly!
Now I have another challenge which requires me to pass a fetchXml instead of the reference and relationship name. Do you have an example how to pass a fetchXml to the Distribute Action and more specifically how to add the GUID of the parent record to the fetchXML string?
Best rgds, Geron
Geron,
If you want to pass anything to an action – just add another one Input to the action and you’re done. In order to use Id of the record you can use “Get Record Details” step of the UWT. To build the fetch you can use String – Combine operation.
Thanks,
Andrew
Hi Andrew,
I am posting another queestion here since I do not see an option for me to contact you.
Is it possible with UWT to lookup a record using fetchXML and use the returning GUID to populate a lookup field. I have tried multiple combinations of action in the UWT but cannot seem to find the right one. If this is possible, can you explain which actions from UWT to use and in which order?
Thanks for you prompt reply,
Geron
Geron,
You can post your questions here or open an issue on the GitHub where I believe you downloaded solution from.
To answer your question I want to understand how do you plan to use that lookup field. Can you please explain that?
Thanks,
Andrew
Hi Andrew,
I created a fetchXML to lookup a record in a masterdata table and return a GUID. This GUID I want to save in the entity record that I running the workflow on and in doing so create a link between these two records.
Thanks Geron
Geron,
I’m not sure regarding your scenario. Look me up at the LinkedIn and let’s chat there.
Andrew
Hi Andrew,
Would you be able to use UWT to handle adding the ability to add multiple Contacts to a Lead and then once that Lead is Qualified, associate those Contacts with the created Account?
Thank you again for the amazing solution. I have used it for many relationships.
Hello Mike,
I’m not fully certain regarding your scenario. Correct me if I’m wrong – you have lead and you have multiple contacts attached to that lead. Once lead is qualified those contacts should be associated to account. Is that correct scenario?
Andrew