Use Microsoft Flow to: Copy a Qualified Lead’s Notes to the new Opportunity
The qualification or disqualification of a Lead in Dynamics 365 is a human triggered event that kicks off a predefined process. That process will convert the Lead to a new Contact and Account record and also create an Opportunity that is associated with the Contact and Account. There will also be a link back to the originating lead in the Opportunity record.
But what happens to important pieces of information that were recorded in the CRM user’s conversations with the Lead? Absolutely nothing! They stay with the Lead record and remain several clicks away from the Opportunity record and are basically out of sight and out of mind.
I started thinking about how to solve this challenge with Microsoft Flow after seeing a post on the CRMUG Community support forum.
This is what I have come up with as one approach to copy the Notes and attachments to the Opportunity record automatically. You could also approach it differently by changing the regarding on the Notes from the Lead record to the new Opportunity record. Modify it to fit the way your company wants it to work.
Here is a big picture of what the Flow looks like. (if it looks a little scrunched on your screen, click on it to get a bigger view):
Let’s break down each step in the Flow:
Step 1 – Listen for the creation of a new Opportunity and then get all the field data from the Opportunity record. We will need some of that info in later steps.
Step 2 – Check to see if the Opportunity was created as a result of the Automated Lead Qualification workflow. We do this by checking to see if the attribute field on the Opportunity record has any data in the Originating Lead Lookup field (look for this in the Marketing section of the Opportunity form)
Step 3 – If it resolves to False, it means the lookup field is not empty, ie it came from a Lead, so then go down the Yes path. If it didn’t come from a Lead conversion we don’t need to do anything so we don’t need any steps for the No result.
Step 4 – Now lets get all the Notes for the Lead record and then loop through them using the Apply to Each function to make a Copy of the Lead Note to a New Note along with the attachment, if any. And set the regarding to the new Opportunity.
There you go. The takeaway is the List and Apply to Each Actions in Microsoft Flow is the greatest thing to happen for us in the Dynamics 365 world.
Hi Jerry,
This is a cool idea to use Flow. I have a question though. I recreated your flow identically and it works as expected. However I wanted to use this same concept to carry over a custom entity that we have linked to the lead and move it to the contact. But when I set it up similar to this flow it loops through ALL of the records for that custom entity instead of just the ones that are related to the Lead. The Flow works as I wanted as it’s setting the link to the contact but it’s also setting all of the records in the system to this one contact. Any thoughts?
Eric,
I now have a template for this blog post on the Flow site. Edit the template to replace the child record with your custom entity.
https://flow.microsoft.com/en-us/galleries/public/templates/cde9de4bdd60459088841badd4adc513/lookup-and-update-child-record-when-a-parent-record-is-updated-in-cds/
Jerry
This is great, but should this be created as a Business Process Flow and not My Flows?
Susan,
How would you get the BPF to iterate through all the Notes?
Unless you are suggesting that it be triggered by the BPF and run asynchronously vs being an instant Flow?
Jerry
Thanks for the reply, reason I asked is because I did create a flow under My Flows but this did not work I am not sure if the flow ran but there is something wrong in the setup of if it was never activated. One main difference I used the Dynamics 365 connector and not the Common Data Service.
Susan,
You definitely need to update your flow to the CDS trigger and action. Did you look in the activity to see if it was triggered?
I am getting close! I created it as a CDS trigger but having problems with the expression for the condition, I get the following error: The template validation failed: The actions(s) ‘Get_Opportunity_Record’ referenced by ‘inputs’ in action ‘Did_it_originate_from_a_Lead’ are not defined in the template.
Thanks I did convert to a CDS trigger, had trouble with the condition expression so I used an alternative. Only problem it copied over all notes and not just the ones related to original lead.
Susan,
See step 4, you must not be filtering correctly – You need to have the correct filter expression in the find leads from the same company action. It should look like this companyname eq ‘@{triggerBody()?[‘companyname’]}’ and statecode eq 0
Jerry
Thanks Jerry for your support and this great blog. Yes it was a filter that was missing the one I added was in the step List Notes for the Lead, advanced options:
_objectid_value eq ‘@{body(‘Get_Lead’)?[‘leadid’]}’
Also because there can be several notes to copy, I wanted them in the same order so I added an order by: createdon asc
The expression had me puzzled for a while, this is my first attempt at a flow and the Advanced option is not available, but I resolved that by first selecting the parameter for originatinglead, is not equal to, and then using the Null function.
This was a fun learning experience and I look forward to creating more flows.
Hi
I’m having difficulty applying this flow to my organization.
I wasn’t able ‘save’ the template to My Flows, so I built a new flow step by step to look exactly like this flow. I saved the flow, and when I log in to us.flow.microsoft.com, I can see the flow under ‘my flows’ on that page.
However within Dynamics 365 (CRM), when I go to Settings > Microsoft Flows, the page says ‘You don’t have any flows.”
You will only see them there if the are part of a solution.
You will see this flow from the Flow drop down when you are on the record.
Thanks Jerry
I was able to get a bit of help from MS support – they advised that the Flows don’t appear in 365 unless they begin with the ‘When a record is selected trigger.’
They referred me to the ‘Tip’ on the bottom of this page: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/admin/enable-embedded-flow-in-your-organization
The Flows menu only list flows that begin with the When a record is selected Common Data Service trigger and contain at least one trigger or action that references that entity.
They assured me that even though I can’t see the Flow in D365, the Flow is functioning. We tested a few times and the Flow does seem to work even though it isn’t visible within D365. Does this sound normal? Since this flow is triggered automatically it wouldn’t necessarily help to have it available from the drop down menu, would it?
The flow should be visible inside of CRM if is was included in the solution that was imported into CRM.
Jerry
That is correct. It will only appear inside of CRM if it is built inside of a solution that is imported into CRM.
Jerry
I noticed one issue with this flow – when the notes are copied from the Lead to the Opportunity, the ‘owner’ of the note on the opportunity is changed from the Salesperson to myself. I assume this is because the Flow is connecting to the CDS using my own credentials.
Is there a way to workaround this?
David,
There will be a capability coming to Flow as part of 2019 Wave 2 (October) that will allow you to run an action in an impersonation mode. In the mean time, you would have to update the action to transfer ownership.
Jerry