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 last

Santa
  • Facebook
  • Twitter
  • Print Friendly
  • LinkedIn
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
  • Facebook
  • Twitter
  • Print Friendly
  • LinkedIn

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
  • Facebook
  • Twitter
  • Print Friendly
  • LinkedIn

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
  • Facebook
  • Twitter
  • Print Friendly
  • LinkedIn

DynamicsSolution
  • Facebook
  • Twitter
  • Print Friendly
  • LinkedIn

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
  • Facebook
  • Twitter
  • Print Friendly
  • LinkedIn

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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
      • Facebook
      • Twitter
      • Print Friendly
      • LinkedIn

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.
    requestBin
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
    Copy 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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

    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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

    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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  3. We are going to respond to an HTTP request, so we need to find the HTTP request trigger
    findATrigger
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

    httpTrigger
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  7. Now, let’s click “New step” and “Add an action”
    addAction
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  8. In the Choose an action, we want to look for the “Dynamics 365 – Create a new record” action and select it.
    createNewRecordAction
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

    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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  3. Return to WordPress and Gravity Forms and navigate to your Webhook Feed Settings|
    getToWebhook
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  4. Paste the HTTP Post URL In the Request URL text box.
  5. When you press Update Settings, you might get an error
    webhookUrlError
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

    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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

    webHookUrlFixed
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn
  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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

    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
    • Facebook
    • Twitter
    • Print Friendly
    • LinkedIn

    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:

  • Facebook
  • Twitter
  • Print Friendly
  • LinkedIn

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
  • Facebook
  • Twitter
  • Print Friendly
  • LinkedIn

Submit a Comment

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Our newsletter features the latest in agile thinking and modern web development topics.

You have Successfully Subscribed!