How To Send SMS Notifications to MS Dynamics 365 Campaign Members

March 02, 2022
Written by
Reviewed by
Toby Allen
Twilion
Dan Wong
Twilion

How To Send SMS Notifications to MS DYnamics 365 Campaign Members
Overview

 

How It Works

 

Prerequisites

First, you need to set up your Twilio account, Microsoft account, Dynamics account and purchase a Twilio phone number.

For production 'Dynamics 365 Sales Premium', 'Dynamics 365 Sales Enterprise', or 'Dynamics 365 Sales Professional' license will be needed to use HTTP triggers and Microsoft Dataverse connectors in Power Automate.

Power Automate Setup

The next step is then to import and configure the flow that will be executed on the selected Campaign to send the notification to all Members. This flow will have the below tasks added, which you can configure and edit as needed:

  1. Get campaign full details
  2. Get all campaign marketing lists
  3. Get full details of each marketing list
  4. Get all members of each marketing list
  5. Get full details of each member
  6. Send text in campaign Offer field to all members’ mobile phone

 

Import your flow

Here are the steps to import your flow:

  1. Go to https://flow.microsoft.com and login using your Microsoft Account
  2. Click on the import button in the top right hand corner of the screen
  3. Upload the package .zip file from here and wait for the screen to show up the package details
  4. When configuring the flow settings, you can choose to either create a new flow or update an existing one with the flow definition from the package
  5. You will also need to select the connections that are required to setup the flow as part of the import process. You should see the Import button light up once you have successfully configured all the required settings
  6. Click on Import and wait for the process to be completed

 

[Import your flow - Figure 1]

 

Configure your flow

After importing your flow, you will need to apply some configurations. First, click on My flows & find your flow, then click on the three dots beside your flow and click on Edit (or click on the Edit icon)

[Configure your flow - Figure 2]

Now, find & expand the Initialize variable - varSMSSendFromNumber step to edit, and then set its value to <your-twilio-number>

This will be used as a sender in your notifications sent to members.

[Initialize variable - figure 3]

Next, find and expand When a HTTP request is received step to copy the HTTP POST URL.

The URL will only be available after the flow is saved at least once

[When a HTTP request is received - figure 5]

Finally, click on Back arrow, and then click on Turn on to enable your new flow.

[Turn on your flow - figure 6]

 

Power Apps Configurations

You have now your flow ready to use and its time now to find a way to trigger this flow from within Dynamics 365. You will start by creating a new solution with your entities, and then customise your Campaign form to have a new command button in its command bar. This command will then be used to trigger your flow.

Create your solution (or edit an existing solution)

Here are the steps to create your new solution and customise your Campaign form:

  1. Go to https://make.powerapps.com/ and login using your Microsoft Account.
  2. Go to your target environment and click on Solutions
  3. Click on New -> App -> Model-driven app from blank
  4. Choose Modern app designer, then click on Create
  5. Type in Name and description, then click on Create
  6. Wait until App is created, then under Pages, click on Add page
  7. Choose Table based view and form, then click on Next
  8. Search for Campaign, Marketing List & Contact to select the three of them, then click on Add
  9. Click on Publish to save & publish your App. The Application home page should look similar to the screen below.

[Create your new solution - figure 7]

Create your command

Here are the steps to create your new command:

  1. Click on ellipses beside Campaign (New Page created from previous steps)
  2. Click on Edit command bar
  3. Choose Main form, then click on Edit
  4. Under Commands, click on New Command
  5. Add values to New Command fields as follows:
    • Label: Send SMS
    • Icon: Use Icon (Choose Email icon)
    • Tooltip title: Send SMS
    • Tooltip description: Send SMS to all campaign members using Twilio
    • Action: Run JavaScript
    • Function name: sendCampaign
    • Under Function name, click on Add parameter
    • Under Parameter 1, choose PrimaryControl

Create your web resource

  1. Under Library, click on Add library which open Add JavaScript Library pop up
  2. Click on New, which open Web Resource new tab
  3. Provide values to Web Resource fields as follows:
    • Name: twilio-campaign-trigger
    • Display name: Twilio Campaign Trigger
    • Type: Script(JScript)
  4. Click on Text Editor to add below code, then click Ok
function sendCampaign(primaryControl) {   
    var flowUrl = "<replace-by-your-HTTP POST URL>";
    var input = JSON.stringify({
        "entityId": primaryControl.data.entity.getId().replace("{", "").replace("}", "")
    });
    var req = new XMLHttpRequest();
    req.open("POST", flowUrl, true);
    req.setRequestHeader('Content-Type', 'application/json');
    req.send(input);
}

Now, make sure your web resource look similar to below screen, and then click on Publish All Customizations to publish your changes

[Create your new web resource - figure 8]

Save and publish your form

  1. Go back to the Main Form browser tab with the Add JavaScript Library popup opened
  2. Search for Twilio Campaign Trigger (refresh browser if not found), then click on Add
  3. Make sure you have all values provided, and then click on Save and Publish to publish your customized Main form. Note: The form should look similar to the screen below

[Publish your form - figure 9]

 

Dynamics 365 Configurations

The first step is to configure MS Dynamics to have a campaign with one or more marketing lists. Each marketing list will then have one or more contacts/accounts. (see screen below for more entails)

[Dynamics Introduction - figure 10]

Create your contact(s)

Similar to Microsoft Office Outlook or other email programs, you store data about the people you know and work with in contacts.

Here are the steps to create your new Contact:

  1. Go to https://<replace-with-your-tenant.name>.crm6.dynamics.com/main.aspx and login using your Microsoft Account
  2. In the site map, select Contacts
  3. Specify the details that you know about the contact. (Remember to add a mobile phone number)
  4. (Optional) Specify the account that the contact belongs to. Associating a contact with an account helps in reaching out to the right people to work with an account
  5. Save the changes
  6. Repeat steps 1-5 to add one or more contacts.

[Create your contacts - figure 11]

Create your static marketing list(s)

Here are the steps to create your new Static Marketing List:

  1. In the site map, select Marketing Lists
  2. Select New and on the Summary tab, add the required information. Note: To look up records in the Owner field, first select Save, or you'll lose your changes
  3. Select Save so you can enter information in other areas of the form
  4. Select the Notes tab to add any other information that applies to your marketing list
  5. Select Save
  6. (Optional) Repeat steps 1-5 to create one or more lists

[Create your static marketing list - figure 12]

Manage member(s) in your static marketing list

  1. In the site map, select Marketing Lists
  2. Click on your static marketing list record, select the down arrow next to Manage Members on the command bar, and then select Add using Lookup
  3. In the Lookup Records dialog box, select your search criteria
  4. Select all your contacts that you want to add, and then select Add

[Manage members in your static marketing list- figure 13]

 

Create your dynamic marketing list(s)

Here are the steps to create your new Static Marketing List:

  1. In the site map, select Marketing Lists
  2. Select New and on the Summary tab, add the required information. Note: To look up records in the Owner field, first select Save, or you'll lose your changes
  3. Select Save so you can enter information in other areas of the form
  4. Select the Notes tab to add any other information that applies to your marketing list
  5. Select Save
  6. (Optional) Repeat steps 1-5 to create one or more lists

[Create your dynamic marketing list - figure 14]

Define the member selection criteria for your dynamic marketing list(s)

Here are the steps to add members your new Dynamic Marketing List:

  1. In the site map, select Marketing Lists
  2. Click on your dynamic marketing lists, on the command bar, select Manage Members
  3. In the Manage Dynamic List Members dialog box, the entity that the marketing list is targeted at is automatically selected
  4. In the Use Saved View drop-down box, select a view for the selected entity, which will be used for filtering
  5. Select Add, and then select Add row, to define the search criteria. For example, to find all the contacts in the Seattle city, in the first box select the field as Address 1: City. Then, in the second box, select the query relational operator as Equals. In the third box, type Seattle. You can select fields from the current record type, or from related record types
  6. Select Find
  7. Select Use Query to add the matching records to your dynamic marketing list

[Define member selection criteria for your dynamic marketing list - figure 15]

Create your campaign(s)

Promote your business, expand your reach to new customers, and improve sales by using campaigns in Dynamics 365 Sales. Use campaigns to store all your marketing information and activities, and to measure the success of your efforts. Campaigns contain planning tasks and campaign activities you need to manage for the marketing campaigns. Campaigns can include planning activities that you want to perform before you launch the campaign, and also the campaign activities you want to manage as part of the campaign.

More information can be found in the post Add an activity to a campaign using in-app marketing

Here are the steps to create a new Campaign:

  1. In the site map, select Campaigns
  2. Select New and on the Summary tab, add the required information
  3. Add text to OFFER field. Note: text in the OFFER field will be used in the SMS notifications sent
  4. Select Save

[Create your campaign - figure 16]

Add your marketing list to your campaign(s)

  1. After Campaign is created, under the Marketing Lists area, click on the three dots and choose Add Existing Marketing List
  2. In Lookup Records window, type in nsmer of your your two Marketing List and press enter to search
  3. Click on both of your Marketing Lists found, then click on Add

 

Testing your solution

Now you have everything in place to send a notification through to all members in your Campaign. Below are the steps to follow for testing:

  1. Go to https://make.powerapps.com and login using your Microsoft Account
  2. Under Apps, click on your new App created
  3. Click on your campaign to make sure it has value in the Offer field
  4. Click on your new command Send SMS

Once the flow triggered from your new command run is completed successfully, all Members in all the Marketing Lists of this target Campaign should receive the text you entered in the campaign Description field. You can go to My flows in Power Automate to check the logs and see the status of your target flow.

[Testing your solution - figure 17]

 

What's next?

Congrats! You now can send SMS to all the members of Marketing lists of a Campaign within Microsoft Dynamics 365.

Looking for what to do next? Here's a list of things to try:


 

Further References

Sherief Elzoghby is a Principal Solutions Engineer at Twilio. He has spent the past 17 years working on Microsoft products – and riding his cruiser road motorbike, too – in AU & NZ. He moved to Twilio last year, working closely with customers to help them uncover the hidden powers of modern communications within their applications using Twilio products.