Our Sales team would like to share sales documents related to the specific lead/opportunity.
Server-based SharePoint integration is enabled and we created a modern team site in SharePoint Online where every parent account of the leads will have their own library. For every lead we want to add a folder to the account library and copy a start document to it. A document location to this folder must be added regarding the lead, so there’s instant integration between Dynamics 365 CE and SharePoint.
On lead qualification, the regarding field at the document location record must be updated with the qualifying opportunity so the related documents will be available in the opportunity. The automation solution for this scenario consists of 2 Flows:
1. On creation of the lead: add folder to the account library and create file based on a template; add document location regarding the lead.
2. On status change of the lead: if qualified, then set the regarding field at the document location record to the qualifying opportunity.
– The ‘Parent Account for lead’ field is set as Business required
– Account Number: auto-number attribute with prefix + sequential number (ACC000001); will be used in the url of the account library
– Account Name; will be used as name of the account library
– Sales Number: auto-number attribute with prefix + sequential number (SLS000001) on Lead entity; wil be used as name for folder and document location
– Template document is saved in a document library at the SharePoint site
– SharePoint Site record in Document Management referring to the team site in SharePoint Online.
Here is an overview of Flow 1:
The variable ParentSiteID is set to the ID of the SharePoint Site record in Document Management.
If the Parent Account for lead is not empty, the action Get record will get the account details to set the variables Account Number and Account Name.
We get the file content of the template document and use this to create the folder and file in the account library. But if the account library doesn’t exist, the action will fail. That’s where the configuration for run after comes in. The flow will then continue to run in the Failed scope, and if successful (account library exists) it will continue to run in the Succeeded scope. At last, the first action in “the footer” will start if one scope is successful and the other scope is skipped.
In the Failed scope the account library is created before the folder and file creation retry. In the Succeeded scope the ID of the Account Document Location is fetched.
Failed Scope: the first HTTP request to SharePoint will create the account library with the Account Number as name that is used in the url. The second HTTP request to SharePoint will rename the library to the Account Name. Reference: Working with lists by using REST
Then the folder and file are created. The next action will create a Document Location for the account library.
I’ve tried to create the Document Location for the lead in one step but it’s not possible to use a slash in the Relative URL field. This will give an error in the UI of Dynamics 365 CE, and in Flow as well.
That’s why I get the ID of the created Document Location for the account library and set the variable DocumentLocationID. In the Succeeded scope I only have to lookup the ID of the existing Document Location for the regarding account.
In “the footer” of the Flow the Document Location to the folder regarding the lead is created.
And the last action will create a task regarding the lead to start with the document.
So when a lead is created the Flow will result in an Account library with a folder for every related lead and a start document to fill out and finish the created task. In SharePoint it looks like this:
And when opening the related Documents on the Lead record, the integration is a fact.
The next blog post will be about Flow number 2.