Views:

Scenario Overview

In this scenario we will show you how to use WebFusion to use the Twilio service to send SMS messages from Dynamics 365. In addition we will show you how to use xCache to store and retrieve the static configuration data needed by Twilio to connect and send SMS messages.

North52 Decision Suite

The BPA solution works like this:

  • We create a custom activity entity called SMS. 
  • A Yes/No field on the entity controls when the message is sent.
  • Three xCache records are created to store the Twilio configuration data AccountSID, Token and FromNumber
  • Finally we use the CallRestAPI() function to send the SMS message using data on the SMS entity for the TO Number and the message text

Configure the formula

The following set of steps will set this formula up for you:

  • Create a new formula of type Save - Perform Action
  • Set the Source Entity to SMS
  • Copy and paste the formula below into the formula description field
  • Click Save

 

Note: If the SMS entity does not appear for you then you will need to refresh the Source Entity Cache as shown below in the KB article.

Troubleshooting #08 - Refresh the Source Entity Cache · North52 Support

 

Configure xCache

The following set of steps will set the workflow up for you:

  • Using the main BPA menu bring up the list view of the xCache entity
  • Create a new xCache record as shown in the screenshot below. Please note you will need to substitute in your own Twilio account details as data shown in dummy data.
  • You are ready now to test

Formula

Note the xCache references highlighted in the formula below:

if( [north52_sms.sendmessage] = true ,  

  CallRestAPI(
                  SetRequestBaseURL('https://api.twilio.com/2010-04-01'),
                  SetRequestResource('/Accounts/{0}/Messages.json', xCacheGet('Twilio_AccountSID') ),
                  SetRequestDetails('Post'), 
                  SetRequestHeaders(),
                  SetRequestParams('From', xCacheGet('Twilio_FromNumber'), 'To', '+' + [north52_sms.north52_mobilenumber], 'Body',
                               [north52_sms.north52_message]),  
                  SetRequestAuthenticationBasic(xCacheGet('Twilio_AccountSID'), xCacheGet('Twilio_AccountToken')),
                  SetRequestFiles(),
                  SetRequestExpected('Created'),
                  SetRequestActionPass(
                                                         UpdateRecord('north52_sms',
                                                                                   [north52_sms.activityid] ,
                                                                                   SetAttribute('north52_responsecontent', 'SMS ID:' +
                                                                                                GetVarJsonValue('sid') + ' DateCreated:' +
                                                                                                GetVarJsonValue('date_created')),
                                                                                   SetAttribute('scheduledend', [north52_sms.actualend]),
                                                                                   SetAttribute('actualstart', [north52_sms.actualend]),
                                                                                   SetAttributeStatus(1,217890002)   
                                                       /* Close the record with Sent Status */
                               )
                  ),
                  SetRequestActionFail(
                                 UpdateRecord('north52_sms',
                                             [north52_sms.activityid] ,
                                             SetAttribute('north52_responsecontent', GetVar('responsecontent')),
                                             SetAttributeStatus(0,217890000) /*Set error message*/
                                                                                 )
                                                       )
   ) , 'NoOp')