Working in the construction industry we engage quite a lot of subcontractors. In the past we used to rely on preparing, issuing and executing subcontracts manually.
This article runs through how through the use of SharePoint and Power Automate (Flow) we can track the status of contracts that have been sent and once signed retrieve the completed contract and save to a Sharepoint list.
A couple of things to note:
- You need a subscription with DocuSign
- The DocuSign connector is a premium connector
- At the time of writing the DocuSign connector is still in Preview
- DocuSign has a feature which allows you to have custom fields on an Envelope you are sending out. I will be using these fields to capture additional information
Part 1: The SharePoint List
The first step in setting this up is creating a SharePoint list. There are a couple of ways to set this:
- Using a Document Library and add custom fields
- Using a custom SharePoint list and adding the completed contract as an attachment. (In this article I will be using this option)
I am creating a Sharepoint list called Contract Register and have setup the following columns:
Our goal will be to populate the list with the details for the contract as a contract is sent and completed.
Part 2: Setting up Power Automate
Connecting to the Sandbox / Developer DocuSign environment with Power Automate
When registering with you can get access to a Sandbox / Developer environment, which is handy when testing so that you don’t use up your envelopes.
However there is a trick in setting up access to the Sandbox environment through Power Automate. By default it is hidden from the list of available connectors and you need to make it visible (not sure why you need to do this). But thanks to an post in the Power Automate community I was able to get this up and running
- Go to https://flow.microsoft.com/
- Login with your Office 365 account
- Navigate to Data -> Connections
- At the end of the URL of this page add “?addConnectorHideKey=DocuSignDemo” and press enter
- Select create a new connection, you should now see both DocuSign and DocuSignDemo in the list of connectors for you to connect. Create a new connection to the DocuSignDemo.
- Create a new Flow component to test the workflow with Demo account
Creating the Flow – For Sent Contracts
Once you have the connector setup you can start creating the flow. In order to create the Flow you need to go into Power Automate and select Create. And since we want this process to happen automatically we will need to select Automated Flow
The next step is to add the trigger, in this case we are going to select the trigger “When a envelope status changes”. The first time you add this trigger you will be prompted to login to DocuSign. Once you have logged in you will see the account id will now be available.
The Connect name can be whatever you want it to be. I recommend using something that is relevant to the task you are performing.
There are a couple of Envelope Event options:
Given that you have to select the Envelope event at this stage means that you will need to create separate flows for different events.
Now that we have the trigger we can start adding the actions to capture the data for the contract that has been sent out.
Setting up variables
We will start with initialising some variables based on the Custom Envelope Fields, which will make it easier later on. First we will store the custom fields in an Object variable, then extract the contract number, job number and document type. The names of these fields will depend on what fields are setup in DocuSign you set up if any.
Note: We use the Document Type field so that we can have different actions occur for example we might send out a contract for signing and want it to go into a contract register or we could send out a NDA and need it to be sent to HR
At the same time we can also set the date that the contract / envelope was sent out
Choosing Actions based on Document Type
Once we have the variables setup we can then start to use the information to populate the contract register. Since we are using a document type to control the actions we are going to perform we can use a switch control to determine the next steps.
In this case we will be focusing on the Subcontract (Contract) document type.
Saving details of sent contract
When DocuSign sends an Envelope it creates a unique Envelope Id, we will be using this as an Identifier in the Sharepoint list.
DocuSign also allows you to resend a contract if corrections / alterations have been made and keeping the same Envelope ID, for our scenario we only want to keep the current / latest details. To achieve this we are going to first check if the Envelope ID exists in the Sharepoint list already
To do this we will use the Get Items (Sharepoint) action, which allows us to create a filter based on the Envelope ID field
This will return an array of results. If there are no results then the array will be empty, otherwise it will contain details from the Sharepoint list for the existing record. To test this we can use a condition to check if the length
Once we have checked if the Envelope ID exists we can then either update the existing item in Sharepoint or create a new item
That the entire flow for capturing details for the sent contracts. A couple of things to note:
- We left the Date Completed blank because the contract hasn’t been signed yet
- When updating the item we used the first result returned from checking if the item already existed in Sharepoint, using the following expression
Once a envelope is now sent from DocuSign there will be a record of it been sent in the Sharepoint list, including the details
Creating the Flow – For Completed Contracts
The next Flow that we can look at is the how to pick up the Completed Contract, including the attaching the signed contract to the record in Sharepoint.
Unfortunately due to the way the trigger from DocuSign is setup, we need to set this up as another flow. To start the flow we can follow the same steps above by creating a new Automated Flow
Then add the trigger “When an envelope status changes” for DocuSign, however this time we will use the Envelope Event “Completed”.
The variable setup will mostly be same except for getting the date completed. There is no final completion date available in the results returned, however we can create the date using utcNow() in the “Set Completed Date” action
We can now add an action for retrieving the completed documents. This can be done by adding the “Get envelope documents” action and passing the Envelope ID into the Envelope field.
This action will return a PDF document and if you choose yes in the Certificate of completion field the PDF will include the certificate which DocuSign provides for each completed contract
We can then use the Get Items and filter it by the Envelope ID to retrieve the details for the previously sent item
Once we have the item from Sharepoint we can update the details with the “Update Item” action.
The final step is attaching the Completed Envelope Document to the Sharepoint Item, which can be achieved by the “Add Attachment” action
Once the contract has been completed the Flow will trigger, update the Sharepoint item and attach the completed contract