NotifyUtil - Global
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.
| Name | Type | Description |
|---|---|---|
| None |
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
| Name | Type | Description |
|---|---|---|
| filterSMSCapableNums | Boolean | Optional. Flag that indicates if only numbers that are SMS-capable should be
returned. Valid values:
Default: false |
| notifyGroupSelectorSysId | String | Optional. Sys_id of a Notify group for which to return the notify numbers and
information. Default: All groups |
| sourceSysId | String | Sys_id of the source record for which to return the Notify numbers and information. For example, this could be the sys_id of a record in the Incident [incident] table. |
| sourceTable | String | Name of the table that contains the source record that contains the desired Notify numbers and information. |
| Type | Description |
|---|---|
| confProviders | List of available conference providers. Data type: Array |
| numbers | List of objects, each describing a single Notify number. Data type: Array |
| numbers.defaultFlag | Flag that indicates whether the associated Notify number is the default
number. Possible values:
Data type: Boolean |
| numbers.name | Name or label of the number. Data type: String |
| numbers.number | Notify number. Data type: String |
| numbers.shortCode | Flag that indicates whether the associated Notify number is a short
code. Possible values:
Data type: Boolean |
| numbers.sysId | Sys_id of the Notify number. Data type: String |
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.
| 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. |
| Type | Description |
|---|---|
| String | User SMS-capable telephone number. Returns null if the specified user is not found. |
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);.
| Name | Type | Description |
|---|---|---|
| getData | Boolean | Optional. Flag that indicates whether to return metadata along with the list of
unique phone numbers. Valid values:
Default: false |
| groups | Array | Optional. List of sys_id groups to check. Default: Check all groups. Table: Group [sys_user_group] |
| numbers | Array | Optional. List of specific Notify telephone numbers to check. Default: Check all phone numbers. |
| type | String | Optional. Type of telephone numbers to check. Valid values (case-sensitive):
Default: Check all phone number types |
| users | Array | Optional. List of sys_ids of specific users to check. Default: Check all users Table: User [sys_user] |
| Name | Description |
|---|---|
| numbers | Unique Notify telephone numbers. Data type: Array |
| result | Only returned if getData is set to true. Metadata
associated with each unique number. Data type:
Object |
| result.number | Unique Notify telephone number. Data type: String |
| result.sysId | Sys_id of the record that contains the Notify telephone number. Data type: String Table: Notify Phone Number [notify_number] |
| result.type | Always contains "u" for user. Data type: String |
| result.valid | Flag that indicates whether the Notify telephone number is in valid E.164 format. Possible values:
Data type: Boolean |
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.
| 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. |
| Type | Description |
|---|---|
| Boolean | Flag that indicates whether the specified record has associated active
conference calls. Possible values:
|
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.
- Whether the Notify number exists in the Notify Phone Number [notify_number] table.
- Whether the Notify number has a Notify group associated with it.
- Whether the Notify number is active.
| Name | Type | Description |
|---|---|---|
| number | String | Notify number to validate. |
| Type | Description |
|---|---|
| None |
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.
| Name | Type | Description |
|---|---|---|
| number | String | Telephone number to validate. |
| Type | Description |
|---|---|
| Boolean | Flag that indicates whether the specified number is a valid telephone
number. Possible values:
|
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 '';
}