Send SMS through twilio when high priority incident is created

poojashah27
Giga Guru

Hi,

I have got a new requirement where I need to integrate our Service Now Instance with Twilio. i have already activated Notify plugin and got twilio number, now i need to find a way so that when new critical incident gets created it sends out SMS to the team. FYI half of my team is in india.

Can anyone help me with this?

Thanks

5 REPLIES 5

ChrisPope
Tera Expert

Pooja,



Activate the on-call plugins and these have pre-built and configured workflow to manage this escalation for you.



On-call scheduling



Chris.


Hi Pooja,



If your requirement is just to send SMS automatically to the support group members for high priority incident then use the the Incident alert management(IAM for p1 and p2 tickets) and Notify.



Use this OOB business rule->SMS on new Incident Alert and configure the IAM->contact definitions to user/group(assignmet group).



Note: we need to make little change in the business rule in order to send sms to groups as. changes are in bold



// function to create the sms body


function createSMSBody(record) {



  var incidentAlertMessage = "";


  var iamNumber = record.number;


  var iamSeverity = record.severity.getDisplayValue();


  var iamShortDesc = record.short_description.slice(0,25);


  var iamCustomer = record.source_incident.caller_id.getDisplayValue();


  var iamEventType = record.event_type.getDisplayValue();


  if(record.source_incident != '' && record.source_incident != 'NULL')


  {


  incidentAlertMessage = gs.getMessage("ServiceNow Notification for:{0}, Severity:{1}, Desc:{2}, Customer:{3}", [iamNumber,iamSeverity,iamShortDesc,iamCustomer]);


  }else {


  incidentAlertMessage = gs.getMessage("ServiceNow Notification for:{0}, Severity:{1}, Desc:{2}, Event type:{3}", [iamNumber,iamSeverity,iamShortDesc,iamEventType]);


  }


  gs.log("New Incident sms body : " +incidentAlertMessage);


  return incidentAlertMessage;


}




// function to send alerts


function sendAlerts(notify, incidentManagers) {


  var feedback = "";


  var from = gs.getProperty('com.snc.iam.notify_number', '');


  var notifyUtils = new NotifyUtils();



  if (JSUtil.notNil(notify)) {


  for (var i = 0; i < incidentManagers.length; i++) {


  var manager = new GlideRecord('sys_user');


  manager.get(incidentManagers[i]);



  var numbers = notifyUtils.getUniquePhoneNumbersForUsersAndGroups([], [manager.sys_id + ''], [], notifyUtils.numberType.sms);


  if (numbers.length > 0) {


  notify.sendSMS(from, numbers[0], createSMSBody(current), current);


  feedback += gs.getMessage("Sent SMS to {0} {1}\n", [manager.first_name, manager.last_name]);


  }


  }


  if (feedback != "") {


  current.comments = feedback;


  current.setWorkflow(false);


  current.update();


  }


  } else {


  gs.addErrorMessage("The Notify plugin has to be activated in order to send notifications.");


  }


  return feedback;


}




// get all single user contacts


var notify = new SNC.Notify();


var incidentManagers = [];


var contacts = new GlideRecord('contact');


contacts.addQuery('table', 'incident_alert');


contacts.addQuery('document', current.sys_id);


contacts.addQuery('type', 'sys_user');


contacts.query();


while (contacts.next()) {


  incidentManagers.push(contacts.user.sys_id);


}



//get all group user contacts


var groupContacts = new GlideRecord('contact');


groupContacts.addQuery('table', 'incident_alert');


groupContacts.addQuery('document', current.sys_id);


groupContacts.addOrQuery('type', 'sys_user_group');


groupContacts.query();


while (groupContacts.next()) {


  var grpmem = new GlideRecord('sys_user_grmember');           //To get all Group members list


  grpmem.addQuery('group',groupContacts.group);


  grpmem.query();


  while(grpmem.next())


  {   var phoneNumbr = grpmem.user.sys_id;


  incidentManagers.push(phoneNumbr);


}


}


// send alerts and store result in global variable


var ataken_update = sendAlerts(notify, incidentManagers);



Please let me know if you need anything else


esha3
Kilo Contributor

Hi Vicky,



I tried this after activating the IAM and Notify plugin, but no SMS received.


I did not modify the Business Rule as I need to send SMS to user instead of group.



which phone number it picks from user record to send SMS and how it identifies to which country the number belongs to?


Please confirm. Thank you.


esha3
Kilo Contributor

Also, Are not we required to add the Twilio account to send SMS?