Creating Leads in Dynamics 365 Using Microsoft Flow

Creating Leads in Dynamics 365 Using Microsoft Flow

Microsoft Flow is a tool that can create automated processes across many applications such as Twitter, SharePoint, Outlook and Dynamics 365. It can help automate processes in ways not possible before in previous versions of CRM. All of this can be done without the use of a developer, which saves time and money. This article will focus on the steps to configure MS Flow to automate Lead creation in CRM from an external website. Previously, if you wanted a visitor filling out contact information on your website to automatically be created as a Lead in Dynamics, you would have to spend a lot of time on custom development. With Microsoft Flow, the process is much simpler and streamlined.

Navigate to Microsoft Flow

Go to https://portal.office.com and login with your organization credentials. Once in, click on the “Flow” tile:

O365 Dashboard

Create a New Flow

In the Flow website, click on “My flows”. Then, click on “Create from blank”:

Flow Dashboard

Choose a Trigger Action

Click in the search box that says “Search hundreds of connectors and triggers”. This will take you to a new page. Then type “http” in the search box. Click on “Request – When a HTTP request is received” trigger that comes up in the results:

Flow Step 1

Insert JSON Schema

You have now selected an HTTP trigger. This trigger will fire from the webpage you connect to Flow. You must insert a JSON schema into the trigger. The schema should contain the names of the fields on your webpage that you want to be pushed into Dynamics. Here is an example of what a JSON schema looks like:

{

“$schema”: “http://json-schema.org/draft-04/schema#”,

“type”: “object”,

“properties”: {

“firstName”: {

“type”: “string”

},

“lastName”: {

“type”: “string”

},

“email”: {

“type”: “string”

},

“address”: {

“type”: “string”

},

“city”: {

“type”: “string”

},

“comments”: {

“type”: “string”

},

“company”: {

“type”: “string”

},

“phone”: {

“type”: “string”

},

“region”: {

“type”: “string”

},

“state”: {

“type”: “string”

},

“zip”: {

“type”: “string”

},

“referrer”: {

“type”: “string”

}

},

“required”: [

“city”,

“comments”,

“company”,

“email”,

“firstName”,

“lastName”,

“phone”,

“region”,

“state”

]

}

Once this has been inserted into the Request Body, click the New Step button:

JSON Schema

Add Create Lead Action

After you click the New Step button, you have the option to Add an action or Add a condition. Choose Add an action. In the search box that appears, type “dynamics”. Click “Dynamics 365 – Create a new record” in the results that appear:

Flow Step 2

Configure Record Creation

In the Create a new record action that appears, choose the proper Organization Name from the drop-down. Then choose the correct entity type of the record you wish to create. In this example, we will be creating a Lead record. Once these options are selected, the box will expand to show you all available fields to set for creation:

Configure Lead Creation

Fill in Required Fields

Fill in the required fields for the Lead. The field information brought over from the HTTP request should be available as Dynamic Content to insert into the fields. Any field identified in your JSON schema should be available as dynamic content:

Fill in Lead Fields

Save Flow and Generate HTTP POST URL

Once you have filled in all the fields desired in the Lead creation step, save the Flow using the save button in the upper right-hand corner of the screen.

Copy HTTP POST URL

Take note that once the Flow is saved, the HTTP POST URL has been automatically generated. This is extremely important as this URL connects your website to Flow:

Copy Post URL

Add POST URL to Your Website

On your website, put the auto-generated URL into a new XMLHttpRequest. An example of the function, plus a very simple and testable web form is below. This will show you how this can be done and where the URL could be put in:


<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function () { document.getElementById("submitButton").onclick = submitForm;
};
function submitForm()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", /*"" POST URL Goes in between these quotation marks*/);
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send(JSON.stringify(
{
firstName: document.getElementById("firstName").value,
lastName: document.getElementById("lastName").value,
email: document.getElementById("email").value,
address: document.getElementById("address").value,
city: document.getElementById("city").value,
comments: document.getElementById("comments").value,
company: document.getElementById("company").value,
phone: document.getElementById("phone").value,
region: document.getElementById("region").value,
state: document.getElementById("state").value,
zip: document.getElementById("zip").value, } ));
alert("Thank you!"); /*This is just an additional check to verify the function worked*/
}
</script>
</head>
<p>First Name:</p> <input style="width: 300px;" id="firstName" type="text" />
<p>Last Name:</p> <input style="width: 300px;" id="lastName" type="text" />
<p>Email:</p> <input style="width: 300px;" id="email" type="text" />
<p>Phone:</p> <input style="width: 300px;" id="phone" type="text" />
<p>Company:</p> <input style="width: 300px;" id="company" type="text" />
<p>Address:</p> <input style="width: 300px;" id="address" type="text" />
<p>City:</p> <input style="width: 300px;" id="city" type="text" />
<p>State:</p> <input style="width: 300px;" id="state" type="text" />
<p>Zip:</p> <input style="width: 300px;" id="zip" type="text" />
<p>Region:</p> <input style="width: 300px;" id="region" type="text" />
<p>Comments:</p> <input style="width: 300px;" id="comments" type="text" />
<p><input id="submitButton" type="button" value="Submit" /></p>
</html>

Run Code in Chrome to Test

If you have Notepad++, you can save and run the code from above in a browser. Be sure that you have pasted in your unique POST URL and then saved the code from above. The webpage that opens should look like this:

Simple Form

Fill in Fields and Click Submit Button

Fill in the fields and click the Submit button. Then, navigate back to Flow to see if the job ran:

Form Filled in

Verify if Test Was Successful

Go back to Microsoft Flow and verify that the test ran successfully. If you go back to “My Flows”, you should see a Run History:

Flow Verification

Navigate to Dynamics and Verify that Lead Was Created

Now if we navigate to our Dynamics 365 environment, we can see that the Lead was created successfully. All the fields that we wanted to be populated will have been filled in as we desired.

D365 Verification

Conclusion

Integrating webforms with Dynamics is significantly simplified with Microsoft Flow. The utility of Flow doesn’t stop here, either. You can set up email alerts when a new Lead is created. Or you can assign these new Leads to a user other than yourself. In the past, this process took custom development and was costly. But now, all you need is a little knowledge of JavaScript and you can easily set up webform CRM integration in a simple and cost-effective way.

By | 2018-08-02T15:17:49+00:00 August 1st, 2018|Uncategorized|0 Comments

About the Author:

Philip Frederick
Philip is an experienced CRM System Administrator and IT Business Analyst. As a TrellisPoint Technical Consultant, he provides clients with expert CRM system consulting and training that enables business results.

Leave A Comment