Recently I had to do a demo of Microsoft Dynamics CRM 2011 Online for a customer to show how CRM could work with two-way SMS messages.  I needed to demonstrate sending a message to a contact record and show how I could take the SMS reply, automatically link the reply to the contact record and use it to automate a business process. In the demo I wanted a SMS reply containing the text “SAMPLE” to create a task to send a free sample to the contact to be completed within 24 hours. However the workflow could easily be extended to process any reply message.

XCRM Consultancy and North 52 helped me put this demo and article together, they have even put a PDF guide of this scenario here.

*Important Note* I have been told that in some cases there may be a problem copying and pasting the formulas below as the single quotes   ‘ are being replaced with ‘. To resolve this, replace the quotes with single quotes ‘ or download the formula (much easier) here.

Prerequisites

  • SMS integration tool – I used the solution from xRM Consultancy (download here)
  • N52 Formula Manager – the very flexible rules engine for Microsoft Dynamics CRM from North52 (download here)
  • CRM Online – I set up a free trial at http://crm.dynamics.com
  • SMS Gateway Subscription – xRM Consultancy’s solution uses Esendex (http://www.esendex.co.uk/XRMConsultancy – this URL gives you 100 free messages to enable a thorough test)

Note: All software used in the demo is available for free from the various vendors however for use in production environments please contact the vendors.

Sending the message and handling the replies

We are going to outline how to set your environment up to integrate SMS messaging to your solution below. The basic process flow will be:

a)      Send contact SMS

b)      Contact replies to SMS

c)       SMS reply is forwarded to email address

d)      Email is Tracked in CRM

e)      North52 Formula is executed on the creation of any inbound emails from an email address containing @esendex

f)       The formula logic finds the contact with the associated SMS reply sets the regarding of the email and processes the workflow – in our demo we want to create a task assigned to the contact’s owner.

1. Ensure your recipients can reply to SMS messages

Firstly we need to ensure that recipients can reply to the SMS messages we send. For our trial Esendex account we need to enable the SMS virtual number – contact Esendex support to get this set up. Also we need to ensure that we are not using a ‘Send Alias’ (the send alias allows you to put your company name as the sender rather than a number but makes replies more difficult).

To check/remove your Send Alias open the SMS Configuration: (Settings > Solutions> SMS/Text Messaging from xRM Consultancy > Configuration > Open SMS Configuration

image001

Send Alias field on SMS Configuration page should be left blank unless you include your virtual number in outgoing messages:

image002

2. Set up SMS forwarding for received SMS (Esendex account settings)

To process SMS replies you need to configure your Esendex account to forward SMS replies sent to your virtual number to an email address. For ease of set up we are going to use a standard CRM User account and Outlook tracking to do the integration but in a production environment we would set up a queue and the email router to handle the replies.

Log on to your Esendex Account then navigate to Settings > Receiving > Email forwarding section. Set the email address where you want the received SMS message to go:

image003

3. Set up Formulas to process SMS reply

Process SMS reply email to set Regarding the appropriate Contact

To enable workflow actions that can be associated to the appropriate Contact we need to set the Regarding attribute of the received SMS reply email to the correct Contact record. We do this by matching the inbound SMS number with that of a Contact.

Navigate to Settings > North52 > N52 Formula Manager

Create a new Formula by clicking the New button and set the following properties:

Name: leave default or rename to something more meaningful for you. E.g. SMS Reply – Update Bulk SMS preference

Formula Type: Save – To Current Record

Mode: Server Side

Event: Create

Source Entity: E-mail

Source Property: Sender

Target Entity: E-mail

Target Property: Regarding

image004

Build your formula (or download here)

image005

Copy formula:if(IndexOf([email.sender], ‘esendex’, 0) > -1, SetRegardingLookup(‘contact’,   FindValue(‘contact’,      ‘mobilephone’,      Substring([email.sender], 0, IndexOf([email.sender], ‘@’,0)),      ‘contactid’),   FindValue(‘contact’,      ‘mobilephone’,      Substring([email.sender], 0, IndexOf([email.sender], ‘@’,0)),      ‘fullname’)),‘NoOp’)

Click Save and your formula is ready to test.

4. Process SMS reply email to run workflow and create the task

We need to create the workflow first. If you only want to process one type of reply your workflow would simply be an action to create a Task, however I have shown below how easy it is to set up your workflow to handle multiple reply types and have different business processes start. You could get as complex as you like with the workflow and even send automated SMS replies back to your contact.

The workflow properties

image006

The workflow steps:

image007

The Create Task properties:image008

Next we create a new Formula. Navigate to Settings > North52 > N52 Formula Manager, click the New button and set the following properties:

Name: leave default or rename to something more meaningful for you

Formula Type: Save – Perform Action

Mode: Server Side

Event: Create

Source Entity: E-mail

Source Property: Subject

Stage:   Post-Operation

Note: You will need to enable the advanced view to set the Stage parameter:

image009

image010

Build your formula (or download here) – This formula executes a workflow for the email that is tracked in CRM (uses it’s CRM record ID) and has a sender email address from ‘esendex’ image011

Copy formula:if((IndexOf([email.sender], ‘esendex’, 0) > -1, ExecuteWorkflow(‘SMS Response’, [email.activityid]),‘NoOp’)

Click Save and your formula is ready to test.

Note: The above formulae assume that you only have one contact with the matching incoming mobile number. Numbers must be formatted in an international format e.g. 447712341234 for this to work correctly. N52 Formula Manager can enforce this formatting for all your existing contact records – see the Keeping Mobile Number Formatting Consistent section below.

5. Testing it all works

Send yourself a SMS message – File > New Activity > SMS

image012

image013

Reply to the message: ‘SAMPLE + 1st line address + Postcode’:

image014

You should receive a message in your Outlook in a few secondsimage015

Click Track in CRM from within Outlook (note this would be normally set up with a Queue and be tracked automatically).

The Formula should execute as the email is tracked and created in CRM. It will set the ‘Regarding’ field for the associated contact on the email and execute the SMS Response workflow (which will then create a new task for the contact).

Tracked message with set regarding the correct contact:

image016

The new task created:

image017

Keeping Mobile Number Formatting Consistent

To ensure that you can send SMS messages and receive replies you need to ensure you have mobile numbers recorded in your CRM in the correct format. This can be achieved with a simple formula to enforce a format structure. To keep things simple we are going to require that mobile numbers are recorded in an international format of a between 11 and 15 numbers without a leading 0, e.g. 441212341234. If you wish you could make this +44 (0)12 1234 1234 (note if you do this your formula to manage replies would need to convert the sender number from 441212341234 format to +44 (0)12 1234 1234 to ensure an exact match with the mobile number recorded at the contact level – this can be achieved relatively easily with N52 Formula Manager).

Create another new Formula by clicking the New button and set the following properties:

Name: leave default or rename to something more meaningful for you. E.g. SMS – Contact Mobile field validation Server Side

Formula Type: Validation

Mode: Server Side

Event: Create & Update

Source Entity: Contact

Source Property: Mobile Number

Build your formula:

image018

Copy formula:if(ContainsData([contact.mobilephone]) and RegexIsMatch([contact.mobilephone], «^[1-9]{1}[0-9]{10,15}$»),  ‘NoOp’,  ‘Mobile Phone should be in the international format without a leading 0, +, () or spaces e.g. 447712341234, to ensure SMS delivery and reply matching’)

This posting is provided “AS IS” with no warranties, and confers no rights.

Next time on Mark Margolis’s Blog: Some sample CRM Workshops Questions