---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# NotifyUtil - Global

# NotifyUtil - Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 7 minutes to read

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.
{#NotifyUtilAPI__ul_qvb_kqy_4hb}

## NotifyUtil - NotifyUtil() {#ariaid-title2}

Instantiates a NotifyUtil class object.
{#NU-NotifyUtil__table_e31_kmm_kmb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#NU-NotifyUtil__table_e31_kmm_kmb}  
This example instantiates a NotifyUtil object.

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

## NotifyUtil - getListOfNotifyNumbersAndProviders(String sourceTable, String sourceSysId,
String notifyGroupSelectorSysId, Boolean filterSMSCapableNums) {#ariaid-title3}

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](https://www.servicenow.com/docs/access?context=notify-landing-page&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US)
{#NU-getListNotifyNumsProvids_S_S_S_B__table_pmg_pyt_kmb__entry__3}

| Name | Type | Description |
|-|-|-|
| filterSMSCapableNums | Boolean | Optional. Flag that indicates if only numbers that are SMS-capable should be returned. Valid values: * true: Only return SMS-capable telephone numbers and information. * false: Return all notify telephone numbers and information. 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. |
[Table 2. Parameters]

{#NU-getListNotifyNumsProvids_S_S_S_B__table_pmg_pyt_kmb} {#NU-getListNotifyNumsProvids_S_S_S_B__table_qmg_pyt_kmb__entry__2}

| 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": Boolean, "name": "String", "number": "String", "shortCode": Boolean, "sysId": "String }] |
| numbers.defaultFlag | Flag that indicates whether the associated Notify number is the default number. Possible values: * true: Default number * false: Not the default number 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: * true: Short code * false: Not a short code Data type: Boolean |
| numbers.sysId | Sys_id of the Notify number. Data type: String |
[Table 3. Returns]

{#NU-getListNotifyNumsProvids_S_S_S_B__table_qmg_pyt_kmb}  
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) {#ariaid-title4}

Returns the SMS-capable number associated with the specified Notify user.
{#NU-getSMSNumberForUser_S__table_dkn_1wt_kmb__entry__3}

| Name | Type | Description |
|-|-|-|
| userGROrId | String or [GlideRecord - Global](https://servicenow-prod.fluidtopics.net/nRmUiaC7a08cr2N5iZGqoQ#c_GlideRecordAPI "The GlideRecord API is used for database operations.") | Sys_id of the user record, located in the User \[sys_user\] table, or the sys_user GlideRecord of the user for whom to return the SMS-capable telephone number. |
[Table 4. Parameters]

{#NU-getSMSNumberForUser_S__table_dkn_1wt_kmb} {#NU-getSMSNumberForUser_S__table_ekn_1wt_kmb__entry__2}

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

{#NU-getSMSNumberForUser_S__table_ekn_1wt_kmb}  
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) {#ariaid-title5}

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);`.
{#NU-getUniqPhNumUsersGrps_S_S_S_S_S__table_kxw_hs5_kmb__entry__3}

| Name | Type | Description |
|-|-|-|
| getData | Boolean | Optional. Flag that indicates whether to return metadata along with the list of unique phone numbers. Valid values: * true: Return metadata. * false: Do not return metadata. {#NU-getUniqPhNumUsersGrps_S_S_S_S_S__ul_cjn_1jy_slb} Default: false |
| groups | Array | Optional. List of sys_id groups to check. Located in the Group \[sys_user_group\] table. Default: Check all groups. |
| 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): * voice * sms {#NU-getUniqPhNumUsersGrps_S_S_S_S_S__ul_epz_3t1_lmb} Default: Check all phone number types |
| users | Array | Optional. List of sys_ids of specific users to check. Located in the User \[sys_user\] table. Default: Check all users |
[Table 6. Parameters]

{#NU-getUniqPhNumUsersGrps_S_S_S_S_S__table_kxw_hs5_kmb} {#NU-getUniqPhNumUsersGrps_S_S_S_S_S__table_lxw_hs5_kmb__entry__2}

| 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": "String", "sysId": "String", "type": "String", "valid": Boolean } |
| result.number | Unique Notify telephone number. Data type: String |
| result.sysId | Sys_id of the record that contains the Notify telephone number. Located in the Notify Phone Number \[notify_number\] table. Data type: String |
| 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: * true: Valid E.164 format. * false: Not in E.164 format. {#NU-getUniqPhNumUsersGrps_S_S_S_S_S__ul_in5_lcy_vmb} Data type: Boolean |
[Table 7. Returns]

{#NU-getUniqPhNumUsersGrps_S_S_S_S_S__table_lxw_hs5_kmb}  
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) {#ariaid-title6}

Determines whether there are any active conference calls for the specified source
record.
{#NU-hasActiveConferenceCalls_S__table_wwv_ktm_kmb__entry__3}

| 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 8. Parameters]

{#NU-hasActiveConferenceCalls_S__table_wwv_ktm_kmb} {#NU-hasActiveConferenceCalls_S__table_xwv_ktm_kmb__entry__2}

| 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. {#NU-hasActiveConferenceCalls_S__ul_ucd_zwm_kmb} |
[Table 9. Returns]

{#NU-hasActiveConferenceCalls_S__table_xwv_ktm_kmb}  
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) {#ariaid-title7}

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.
{#NU-validateOutNotifyPhoneNum_S__ol_ej5_w4t_kmb} If any one of these validations fail, the method throws an exception.
{#NU-validateOutNotifyPhoneNum_S__table_nkw_m4t_kmb__entry__3}

| Name | Type | Description |
|-|-|-|
| number | String | Notify number to validate. |
[Table 10. Parameters]

{#NU-validateOutNotifyPhoneNum_S__table_nkw_m4t_kmb} {#NU-validateOutNotifyPhoneNum_S__table_okw_m4t_kmb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 11. Returns]

{#NU-validateOutNotifyPhoneNum_S__table_okw_m4t_kmb}  
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) {#ariaid-title8}

Verifies that the specified number is a valid E.164 telephone number.
{#NU-validatePhoneNumber_S__table_nyd_b5t_kmb__entry__3}

| Name | Type | Description |
|-|-|-|
| number | String | Telephone number to validate. |
[Table 12. Parameters]

{#NU-validatePhoneNumber_S__table_nyd_b5t_kmb} {#NU-validatePhoneNumber_S__table_oyd_b5t_kmb__entry__2}

| 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. |
[Table 13. Returns]

{#NU-validatePhoneNumber_S__table_oyd_b5t_kmb}  
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 '';
    } 


