The NotifyUtil script include provides utility methods to use when interacting with Notify calls and SMS messages using server-side scripts.

To use this script include you must activate the Notify (com.snc.notify) plugin.

Using the NotifyUtil script include you can:

  • Obtain all of the Notify telephone numbers and related Notify information from a specified source record.
  • Obtain a list of unique Notify telephone numbers.
  • Determine whether there are any active conference calls for the specified source record.
  • Obtain the SMS-capable number associated with the specified Notify user.
  • Validate a specified Notify telephone number.

NotifyUtil - NotifyUtil()

Instantiates a NotifyUtil class object.

Table 1. Parameters
Name Type Description
None

Example

This example instantiates a NotifyUtil object.

var notifyUtil = new NotifyUtil(); 
notifyUtil.getTelephonyProviers();

NotifyUtil - getListOfNotifyNumbersAndProviders(String sourceTable, String sourceSysId, String notifyGroupSelectorSysId, Boolean filterSMSCapableNums)

Returns all of the Notify telephone numbers and related Notify information from a specified source record, such as an incident.

You can use this information to initiate a call or send an SMS message on a particular source record. The information that is returned is based on the configuration of the Notify Provider Selector framework. For additional information, see Notify

Example

This example shows how to obtain the Notify telephone numbers and related Notify information from a specified source record.

function updateConferenceBridges(sourceTable, sourceId) {

  var notifyUtil = new global.NotifyUtil();
  var numbersAndProviders = notifyUtil.getListOfNotifyNumbersAndProviders(sourceTable, sourceId);
  var confBridges = [];
  if (numbersAndProviders.confProviders) {
    numbersAndProviders.confProviders.forEach(function(provider){
    confBridges.push(provider);
    });
  }
  if (numbersAndProviders.numbers) {
    numbersAndProviders.numbers.forEach(function(number){
      confBridges.push(number.name);
    });
  }
} 

NotifyUtil - getSMSNumberForUser(String userGrOrId)

Returns the SMS-capable number associated with the specified Notify user.

Table 4. Parameters
Name Type Description
userGROrId String or GlideRecord - Global Sys_id of the user record,

Table: User [sys_user] table or the sys_user GlideRecord of the user for whom to return the SMS-capable telephone number.

Table 5. Returns
Type Description
String User SMS-capable telephone number. Returns null if the specified user is not found.

Example

This example shows how to obtain an SMS-capable telephone number using the associated GlideRecord.

var sourceRecord = new GlideRecord('incident');
sourceRecord.query();
if (sourceRecord.next()) {
  var fromNumber = getFromNumber();
  var nUtil = new NotifyUtil();
  var toNumber = nUtil.getSMSNumberForUser(sourceRecord.assigned_to.getRefRecord());
  var message = 'Incident ' + sourceRecord.getDisplayValue() + ' has been assigned to you.';
  if (fromNumber && nUtil.validateOutboundNotifyPhoneNumber(fromNumber) && toNumber && nUtil.validatePhoneNumber(toNumber)) {
    var notifySMS = new NotifySMS();
    notifySMS.sendToNumber(fromNumber, toNumber, message, sourceRecord);
  }
}

function getFromNumber() {
  var prop = gs.getProperty('custom_property_name', '');
  if (!prop){
    return getFallbackFromNumber();
  }
  return prop;
} 

function getFallbackFromNumber() {
  var notifyNumGr = new GlideRecord("notify_number");
  notifyNumGr.addActiveQuery();
  notifyNumGr.addQuery('has_sms_out', 'yes');
  notifyNumGr.query();
  if (notifyNumGr.next()) {
    return notifyNumGr.number + '';
  }
  return '';
} 

NotifyUtil - getUniquePhoneNumbersForUsersAndGroups(Array numbers, Array users, Array groups, String type, Boolean getData)

Returns a list of unique Notify telephone numbers.

If you don't pass any parameters in the call, all Notify numbers within the Notify Phone Number [notify_number] table are checked for duplicates, with each available phone number only appearing once in the returned list. You can refine the return results by specifying a list of users or groups to check, or by specifying a set of numbers or number types (SMS or voice.) You can also request that the metadata associated with each number be returned along with the unique numbers. If you do not want to use a parameter, simply pass null as a placeholder. For example: return nUtil.getUniquePhoneNumbersForUsersAndGroups(null, userIds, null, 'sms', false);.

Example

This example shows how to request a specific set of unique Notify telephone numbers that have SMS capabilities.

var fromNumber = getFromNumber();
var toNumbers = getRecipientNumbers();
var message = 'This is an example SMS';
var sourceRecord = new GlideRecord('incident');
sourceRecord.query();
if (sourceRecord.next()) {
  var notifySMS = new NotifySMS();
  notifySMS.sendToNumber(fromNumber, toNumbers, message, sourceRecord);
}

function getRecipientNumbers() {
  var userGr = new GlideRecord('sys_user');
  userGr.addActiveQuery();
  userGr.addQuery('first_name', 'STARTSWITH', 'A');
  userGr.setLimit(5);
  userGr.query(); 
  var userIds = [];
  while (userGr.next()) {
    userIds.push(userGr.getUniqueValue());
  }
  if (userIds.length > 0) {
    var nUtil = new NotifyUtil();
    return nUtil.getUniquePhoneNumbersForUsersAndGroups(null, userIds, null, 'sms', false);
  } 
}

function getFromNumber() {
  var prop = gs.getProperty('custom_property_name', '');
  if (!prop){
    return getFallbackFromNumber();
  } 
  return prop; 
}

function getFallbackFromNumber() {
  var notifyNumGr = new GlideRecord("notify_number");
  notifyNumGr.addActiveQuery();
  notifyNumGr.addQuery('has_sms_out', 'yes');
  notifyNumGr.query();
  if (notifyNumGr.next()) {
    return notifyNumGr.number + '';
  }
  return '';
}

NotifyUtil - hasActiveConferenceCalls(String sourceRecSysId)

Determines whether there are any active conference calls for the specified source record.

Table 8. Parameters
Name Type Description
sourceRecSysId String Sys_id of the record to check for active conference calls. For example the sys_id of a record in the Incident table.
Table 9. Returns
Type Description
Boolean Flag that indicates whether the specified record has associated active conference calls.
Possible values:
  • true: Active conference calls are available for the specified record.
  • false: No active conference calls.

Example

This example displays an information message if there are any active conference calls associated with an incident record.

(function executeRule(current, previous /*null when async*/) {
  var nUtil = new NotifyUtil();
  if (nUtil.hasActiveConferenceCalls(current.getUniqueValue())) {
    gs.addInfoMessage("There are active conference calls related to this Incident.");
  } 
})(current, previous);

NotifyUtil - validateOutboundNotifyPhoneNumber(String number)

Validates a specified Notify telephone number.

The method performs three types of validation:
  1. Whether the Notify number exists in the Notify Phone Number [notify_number] table.
  2. Whether the Notify number has a Notify group associated with it.
  3. Whether the Notify number is active.
If any one of these validations fail, the method throws an exception.
Table 10. Parameters
Name Type Description
number String Notify number to validate.
Table 11. Returns
Type Description
None

Example

This example illustrates how to validate a notify number.

var sourceRecord = new GlideRecord('incident');
sourceRecord.query();
if (sourceRecord.next()) {
  var fromNumber = getFromNumber();
  var nUtil = new NotifyUtil();
  var toNumber = nUtil.getSMSNumberForUser(sourceRecord.assigned_to.getRefRecord());
  var message = 'Incident ' + sourceRecord.getDisplayValue() + ' has been assigned to you.';
  if (fromNumber && nUtil.validateOutboundNotifyPhoneNumber(fromNumber) && toNumber && nUtil.validatePhoneNumber(toNumber)) {
    var notifySMS = new NotifySMS();
    notifySMS.sendToNumber(fromNumber, toNumber, message, sourceRecord);
  }
}

function getFromNumber() {
  var prop = gs.getProperty('custom_property_name', '');
  if (!prop){
    return getFallbackFromNumber();
  }
  return prop;
} 

function getFallbackFromNumber() {
  var notifyNumGr = new GlideRecord("notify_number");
  notifyNumGr.addActiveQuery();
  notifyNumGr.addQuery('has_sms_out', 'yes');
  notifyNumGr.query();
  if (notifyNumGr.next()) {
    return notifyNumGr.number + '';
  }
  return '';
} 

NotifyUtil - validatePhoneNumber(String number)

Verifies that the specified number is a valid E.164 telephone number.

Table 12. Parameters
Name Type Description
number String Telephone number to validate.
Table 13. Returns
Type Description
Boolean Flag that indicates whether the specified number is a valid telephone number.
Possible values:
  • true: Valid E.164 telephone number.
  • false: Invalid telephone number.

Example

This example illustrates how to validate a telephone number.

var sourceRecord = new GlideRecord('incident');
sourceRecord.query();
if (sourceRecord.next()) {
  var fromNumber = getFromNumber();
  var nUtil = new NotifyUtil();
  var toNumber = nUtil.getSMSNumberForUser(sourceRecord.assigned_to.getRefRecord());
  var message = 'Incident ' + sourceRecord.getDisplayValue() + ' has been assigned to you.';
  if (fromNumber && nUtil.validateOutboundNotifyPhoneNumber(fromNumber) && toNumber && nUtil.validatePhoneNumber(toNumber)) {
    var notifySMS = new NotifySMS();
    notifySMS.sendToNumber(fromNumber, toNumber, message, sourceRecord);
  }
}

function getFromNumber() {
  var prop = gs.getProperty('custom_property_name', '');
  if (!prop){
    return getFallbackFromNumber();
  }
  return prop;
} 

function getFallbackFromNumber() {
  var notifyNumGr = new GlideRecord("notify_number");
  notifyNumGr.addActiveQuery();
  notifyNumGr.addQuery('has_sms_out', 'yes');
  notifyNumGr.query();
  if (notifyNumGr.next()) {
    return notifyNumGr.number + '';
  }
  return '';
}