Skip to content

Getting into the Flow of the Holiday Season with Dynamics 365 and Microsoft Flow

I’m excited to announce that we have an amazing new Dynamics 365 client. We were contacted this lastSanta week from a representative of none other than Santa Claus himself. It seems that Old Saint Nick is a bit of a tech nerd and has really wanted to streamline his mail room floor operations. Recently Santa and Mrs. Claus came across WordPress and thought it would be a great platform for them to use to build a letter writing system to help more children to easily send letters to Santa.

While WordPress allowed him to quickly create a Letter to Santa tool for their Web site, Santa is a bit worried at how many letters they are expecting to receive and wants to find an efficient way to handle those letters. And, by the way, the letter system is already open, and he needs something as FAST as humanly possible.

So, we had to get creative and figure out how we could quickly build a system to help Santa and his mailroom elves to stay on top of the massive influx of letters they are expecting soon. We turned to Dynamics 365 to create a Mail Room Management System and were able to create a fully integrated system in less than a day! Santa is ecstatic and is confident that this system will truly make his life much better.

Here is how we did it.

The Mail Room System

Let’s start by looking at the process we needed to implement. We want to accept letters from an external WordPress site, give Santa the ability to respond to the letters, and automatically deliver Santa’s response email once Santa is complete.

mailroomFlow

Santa has his WordPress site ready to go and is using Gravity Forms to capture the letters. He doesn’t want to change the site as he is happy with everything he has there. However, he finds the letter response process tedious because, currently, he has to open the form in WordPress, create a new email in his email system, and send it from there. He would like something that better helps him manage his incoming letters and handle all of this from a single system.

letterToSantaWordPress

We used Dynamics 365 to create a mailroom system that consists of a Letter to Santa entity that captures the fields from the WordPress form, gives Santa a nice dashboard to track everything, and an easy workflow to track his process. Santa has allowed us to offer this solution for download, so you can import it yourself to see how we built the Dynamics 365 portion of the system.

mailRoomDynamicsDashboard

DynamicsSolution

How we did it

Integrating with WordPress using Flow

While the Mailroom manager app gives Santa the management functionality he wanted, we still need to get the letters in and out of the system. Traditionally, we would use the SDK to integrate WordPress and Dynamics, but this is time-consuming and requires a lot of custom code. We needed a quick solution that is easy to keep up.

This is where Microsoft Flow comes in. Microsoft Flow is an integration platform that allows you to connect a variety of data sources together in a configurable, events driven interface. Microsoft Flow is included in Dynamics 365 Enterprise subscriptions, but there is also a free edition available that would work for many systems.

We decided to use Microsoft Flow and the Gravity Forms web hook add-on to do our integration. You can follow along with these steps to create a Flow that integrates with WordPress yourself.

Add WebHook capability to Gravity Forms

To begin, let’s go to WordPress and add the Webhooks add-on to Gravity forms. Webhooks is available as an Elite Add-On in Gravity Forms.

webhooksAddon

Once we activate the Webhooks add-on, we need to configure the Webhook feed settings. We go to our Letter to Santa form and create a Webhook feed. Once we create the feed, we need to get a sample of the JSON so we can use that in a bit to configure our Microsoft Flow. We can use RequestBin to capture sample JSON from our Form.

  1. Go to http://requestb.in/ and click “Create a RequestBin”
    requestBinLanding
  2. Copy the Bin URL
  3. Return to the Gravity Forms Feed settings
    1. Set the Request URL to the Request Bin URL
    2. Select Request method “POST”
    3. Select Request format “JSON”
    4. Don’t add any Request Headers
    5. Select Request Body: Select Fields
    6. Add each field you want to submit to Dynamics and give it a key name, you will use this key name to map data in Flow.
    7. Press Update Settings
      webhooksSetup

Get a sample of the JSON

  1. Now, go submit an entry on your form in WordPress and return to your Request Bin
  2. Return to Request Bin and you will see the details of the response that was just made.
    requestBinCopy the “Raw Body” JSON as you will use this in a little bit.

Build a Flow in Dynamics that responds to web hooks

  1. Now, you will need to login to your Dynamics 365 tenant, and select Microsoft Flows from the Settings section of the default site map.
    microsoftFlowsSiteMap
    If you don’t have this in your site map, you can go to flows.microsoft.com and login using the same credentials you use to access CRM.
  2. If you clicked on the “Microsoft Flows” link in the sitemap, you can click the “Create from blank” button:
    createFlowDynamics
    If you accessed through flows.microsoft.com, you’ll need to click “My Flows” located in the nav bar and then click the “Create from blank” button|
    createFlowFlows
  3. We are going to respond to an HTTP request, so we need to find the HTTP request trigger
    findATrigger
    httpTrigger
  4. Once we select the “Request – When a HTTP request is received” trigger, you can give your Flow a name (we used Santa’s Letters from WordPress).
    createWordPressFlow
  5. To define the schema, we click “use sample payload to generate schema”, paste the JSON Schema we captured from Request Bin into the text box, and press done.
    jsonSchema
  6. When we press done, Flow generates a JSON Schema for us. However, it did not detect that our age was in fact a number, so we needed to change the “age” field to “type” : “number” before we proceeded.
    fixSchema
  7. Now, let’s click “New step” and “Add an action”
    addAction
  8. In the Choose an action, we want to look for the “Dynamics 365 – Create a new record” action and select it.
    createNewRecordAction
  9. Next, we select the Dynamics 365 organization we want to integrate with (Letter to Santa in our case) and the Entity Name (Letters to Santa)
    selectOrgNameEntity
  10. Now, we see all of the required fields that are part of the entity. We can view all of the fields by selecting “show advanced options”
    showAdvancedOptions
  11. When you click on a field the content fly-out pops up showing you the fields created in the HTTP Request trigger. You can click on a field in the fly-out to have flow populate the data from the HTTP request into the new record. It is important to note that if you have an option set, you will need to determine the actual numeric value for an option. You can do that from the solution builder in Dynamics. Here is our completed “Create a new record” action:
    completeCreateNewRecord
    You’ll notice that in the Age and Gender field, we used a formula. Flow allows you to create formulas to calculate values. We use a simple INT conversion to convert our JSON Number field to an int and we use a nested if statement to determine the Gender option value

     (if(equals(triggerBody()?['gender'], 'Boy'),206290000,if(equals(triggerBody()?['gender'], 'Girl'),206290001,206290002))
  1. Once we’ve mapped all of our fields, we can click Save Flow and then Done to activate our flow
    activateFlow.png
  2. Before we leave our flow, we need to capture the HTTP Post URL and save that in our Gravity Forms webhook feed. To View the HTTP Post URL that was generated on save, click the “When a HTTP request is received” trigger and copy the HTTP Post URL Text.
    httpPostUrl
  3. Return to WordPress and Gravity Forms and navigate to your Webhook Feed Settings|
    getToWebhook
  4. Paste the HTTP Post URL In the Request URL text box.
  5. When you press Update Settings, you might get an error
    webhookUrlError
    If you receive this, you will need to change your URL a bit, locate the “%2F” special codes in your URL and change them to /
    webHookUrlThingToFix
    webHookUrlFixed
  6. Now everything is hooked up. Go to your form in WordPress and submit an entry then refresh the data in your Dynamics account. If everything is correct, you will now see a new record in CRM!
    letterArrived

Automatically sending the letter

Now that’s great, we are successfully getting WordPress form entries loaded into Dynamics. Now Santa wants to automatically send his responses to the email address on file. To do that, we want to send an email whenever a CRM Entity is updated and the status is set to “Ready”.

  1. The first thing we needed to do to do this is to activate Change tracking on the CRM Entity itself.
    changeTracking.png
  2. Once change tracking is activated, we needed to create a new flow the same way we created our first flow. This time however, we want to use the “When a record is updated” Dynamics 365 trigger.
    dynamics365Connector.png
  3. Once we select the Dynamics 365 – When a record is updated trigger, we select our organization name and entity name (Letter to Santa / Letters to Santa)
  4. Now, we want to add a condition since we only want to send the letter when our Letter status is equal to our Ready status. Click New step then Add a condition
    selectCondition
  5. In the condition box, select Letter Status, select “is equal to” and enter the option set value (206290002…you can look this up in the Dynamics 365 solution builder if you need to).
    configureCondition

Sending an email

  1. Now that our condition is setup, lets add an action inside our Yes block and locate the “Send an email notification” action
    emailProvider
  2. Once we have our action, we can select the Email address field for our To block, we enter “A letter from Santa to “ + First Name in the Subject, and the Letter from Santa field for our email body.
    emailSettings.png
    While this email notification action sends an email from the Microsoft Flow system. You can use Outlook, SendGrid or Gmail (among others) to send an email by selecting those actions and configuring your connection. We used this action as it doesn’t require any additional configuration.
  3. Finally, we want to update the Letter status and Send date on our record to ensure Santa knows we sent the letter. We are going to add another action after our send email notification and look for the Dynamics 365 – Update a record action. Once we find it, we need to map the values as follows:
    updateRecordComplete.png
    You have to map ALL of the values, even ones that don’t change, as there is not a Update changed fields action at this time.

The completed system

That’s it. Once you save the flow and Activate it, you now have a fully integrated Letter from Santa system. Our complete end to end process now looks like this:

You can use Microsoft Flow in your own Dynamics 365 applications to easily integrate Dynamics with an unlimited number of external connections. If you can’t find a connector that works for you, you can create your own connector using the Flow SDK.

Please feel free to ask any questions you might have in how to integrate Flow with your Dynamics applications. You can reach out to us on Twitter @sigaostudios or Facebook or drop me an email at chris@sigaostudios.com. I look forward to hearing from you. If you would like to download the sample solution we created, you can do it here:

[download id=”6229″]

AND, Have a Merry Christmas, Happy Holidays and a great new year!

Santa.jpg