{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1144,"path":"api-reference/server-api-reference/notifyScopedAPI.md","title":"NotifyScoped - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# NotifyScoped- Scoped\n\nThe NotifyScoped API allows you to interact with Notify calls and SMS messages using scripts.\n\nExecute the NotifyScoped class and its associated methods from the `sn_notify` namespace.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## NotifyScoped - call\\(String notifyPhoneNumber, String toPhoneNumber, GlideRecord conferenceCall, GlideRecord conferenceCallRecord, String userSysId, String groupSysId, GlideRecord sourceRecord\\)\n\nCalls the specified E.164-compliant telephone number.\n\n<table id=\"table_qk4_txx_zfb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nnotifyPhoneNumber\n\n</td><td>\n\nString\n\n</td><td>\n\nNotify phone number from which to make the call. When you initiate a call, the outgoing call workflow for the number group associated with this number runs. Ensure this workflow includes a **join conference call** activity to connect the user to the conference call.\n\n</td></tr><tr><td>\n\ntoPhoneNumber\n\n</td><td>\n\nString\n\n</td><td>\n\nPhone number to call. Called numbers are added to the conference call.\n\n</td></tr><tr><td>\n\nconferenceCall\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nOptional. If this parameter is passed in, the callers identified in the **toPhoneNumber** parameter are automatically joined into the conference call identified by this record. GlideRecord for the Notify Call \\[notify\\_call\\] table which identifies the conference call record. This record is automatically added to the outgoing call workflow scratchpad as the workflow.scratchpad.conference\\_call variable.\n\n</td></tr><tr><td>\n\nuserSysId\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Unique identifier \\(sys\\_id\\) of the user associated with the call.\n\n</td></tr><tr><td>\n\ngroupSysId\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Unique identifier \\(sys\\_id\\) of the group associated with the call.\n\n</td></tr><tr><td>\n\nsourceRecord\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nOptional. Source record that prompted this call.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThis example illustrates how to initiate a call to another phone number.\n\n```\nvar from = '+14048007337';\nvar to = '+31646810495';\n\n// set up call\nnew sn_notify.NotifyScoped().call(from, to);\n```\n\nThis example illustrates how to initiate a call to a list of telephone numbers and automatically join those numbers into a new conference call.\n\n```\nvar notify = new sn_notify.NotifyScoped();\nvar from = '+14041234567';\nvar participants = ['+31612345678', '+31623456789', '+31687654321'];\n\n// set up a conference call\nvar conferenceCall = notify.conferenceCall();\n\n// set up the outbound calls for all conference call participants\nfor (var i in participants) {\n    var to = participants[i];\n    notify.call(from, to, conferenceCall);\n}\n```\n\n## NotifyScoped - conferenceCall\\(GlideRecord sourceRecord\\)\n\nCreates a new conference call GlideRecord.\n\n|Name|Type|Description|\n|----|----|-----------|\n|sourceRecord|GlideRecord|Optional. Record that initiated the request to create the conference call. Used to populate the source and table fields on notify\\_conference\\_call record.|\n\n|Type|Description|\n|----|-----------|\n|GlideRecord|New Notify conference call \\[notify\\_conference\\_call\\] record.|\n\n```\nvar notify = new sn_notify.NotifyScoped();\nvar from = '+14041234567';\nvar participants = ['+31612345678', '+31623456789', '+31687654321'];\n\n// set up a conference call\nvar conferenceCall = notify.conferenceCall();\n\n// set up the outbound calls for all conference call participants\nfor (var i in participants) {\n    var to = participants[i];\n    notify.call(from, to, conferenceCall);\n}\n```\n\n## NotifyScoped - dequeueCall\\(GlideRecord callRecord\\)\n\nResumes a call after it was put in a queue \\(on hold\\).\n\nUse this method to resume calls that were put in a queue with the queueCall\\(\\) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|callRecord|GlideRecord|GlideRecord object on the Notify Call \\[notify\\_call\\] table with the held call you want to resume.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to reactivate a call that was put on hold.\n\n```\nvar notifyCallGr = new GlideRecord('notify_call');\nnotifyCallGr.get('active participant sys id');\n \nif (notifyCallGr.isValid) {\n    sn_notify.NotifyScoped.dequeueCall(notifyCallGr);\n}\n```\n\n## NotifyScoped - forwardCall\\(GlideRecord call, String destination, String dtmf\\)\n\nForwards the specified call to a different call recipient.\n\n|Name|Type|Description|\n|----|----|-----------|\n|call|GlideRecord or String|Notify call record or the telephony provider call ID, of the call to be forwarded.|\n|destination|GlideRecord or String|Notify phone number record or an E.164-compliant phone number, of the caller to which to forward the call.|\n|dtmf|String|Dual Tone - Multi Frequency \\(DTMF\\) code to send upon call connection.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to forward a call to another phone number.\n\n```\nvar callID = 'CA92374b5aa561dab476a7001db6026edc'; // Twilio Call ID\nvar phoneNumber = '+91406xxxxxxx';\nvar dtmfTones = null;\n \nvar notifyCallGr = new GlideRecord('notify_call');\nnotifyCallGr.get('active participant sys id');\n \nif (notifyCallGr.isValid) {\n    sn_notify.NotifyScoped.forwardCall(notifyCallGr(or) callID, phoneNumber, dtmfTones)\n}\n```\n\n## NotifyScoped - getAvailableClients\\(String notifyNumber\\)\n\nReturns a list of client sessions that are available to receive calls.\n\n|Name|Type|Description|\n|----|----|-----------|\n|notifyNumber|String|Valid Notify phone number.|\n\n<table id=\"table_jxd_kk2_1gb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nArray\n\n</td><td>\n\nGlideRecord from the notify\\_client\\_session table for the specified phone number. Returns \"0\" if there are no available client sessions.\n\n</td></tr></tbody>\n</table>The following example shows how to use the getAvailableClients\\(\\) method to index into the notify\\_client\\_session table and then iterate across all available Notify clients.\n\n```\nvar clientSessionGr = sn_notify.NotifyScoped.getAvailableClients('+185xxxxxxxx'); \n// Here clientSessionGr is of type GlideRecord on 'notify_client_session' table.\n \nvar isLoggedInUserAvailable = false;\nwhile (clientSessionGr.next()) {\n  if (clientSessionGr.user == gs.getUserID())\n    isLoggedInUserAvailable = clientSessionGr.available;\n}\ngs.info('isLoggedInUserAvailable - ' + isLoggedInUserAvailable);\n```\n\n## NotifyScoped - getPhoneNumbers\\(\\)\n\nReturns all phone numbers and short codes available to Notify.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Array|List of NotifyPhoneNumber objects, each object representing one phone number available to Notify.|\n\nThis example illustrates how to obtain the Notify phone numbers and then iterate over the list.\n\n```\n// Instantiate notify\nvar notify = new sn_notify.NotifyScoped();\n\n// Retrieve all available phone numbers\nvar phoneNumbers = notify.getPhoneNumbers();\n\n// Iterate over phone numbers\nfor (var i = 0; i < phoneNumbers.length; i++) {\n  var number = phoneNumbers[i];\n\n  // Perform any actions using each phone number\n\n}\n```\n\n## NotifyScoped - getShortCodes\\(\\)\n\nReturns all short codes available to Notify.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThis example illustrates how to obtain the Notify short codes and then iterate over the list.\n\n```\n// Instantiate notify\nvar notify = new sn_notify.NotifyScoped();\n\n// Retrieve all available shortcodes\nvar shortCodes = notify.getShortCodes();\n\n// Iterate over phone numbers\nfor (var i = 0; i < shortCodes.length; i++) {\n  var shortCode = shortCodes[i];\n  gs.log(shortCode.getNumber());\n\n//perform any actions using each shortcode\n\n}\n```\n\n## NotifyScoped - getTokens\\(GlideRecord, record\\)\n\nReturns client tokens for any active telephony drivers for use in WebRTC or mobile clients.\n\nThis method uses the currently logged-in user record as the client.\n\n|Name|Type|Description|\n|----|----|-----------|\n|record|GlideRecord|GlideRecord to use to identify the Notify client, such as a group record or a user record.|\n\n|Type|Description|\n|----|-----------|\n|String|Web RTC tokens for the supported drivers, as a JSON string with the following format: \\{driverName1: \"token1\", driverName2: \"token2\"\\}, such as \"TwilioDirect\":\"eyJhxxxx.eyJleHAiOiIxxxx.7fejxxx\\_mbLxxx\"|\n\nThis example shows how to obtain the client tokens for the currently logged in user.\n\n```\n// get Notify client Tokens per active Notify driver for the currently logged in user\nvar json = new sn_notify.NotifyScoped().getTokens();\n \n// Parse the JSON that was return into a tokens object\nvar tokens = JSON.parse(json);\n\n// Log line\ngs.log('Notify client tokens for the currently logged in user');\n\n // iterate over the driver tokens\nfor (var driver in tokens) {\n \tgs.log(driver + ' Driver token: ' + tokens[driver]);\n}\n```\n\nThis example shows how to obtain the client tokens for every Notify group.\n\n```\n// instantiate Notify\nvar notify = new sn_notify.NotifyScoped.Notify();\n \n// get all Notify Groups\nvar notifyGroup = new GlideRecord(\"notify_group\");\nnotifyGroup.query();\n \n// iterate over all notify groups\nwhile (notifyGroup.next()) {\n  // generate Notify Client tokens per active Notify Driver for this group\n  var json = notify.getTokens(notifyGroup);\n  var tokens = JSON.parse(json);\n \n  for (var driver in tokens) {\n    gs.log(gs.getMessage(\"Notify Client token for {0} driver and Notify Group '{1}': {2}\", [driver, notifyGroup.getValue('name'), tokens[driver]]));\n  }\n}\n```\n\nThis example illustrates how to obtain the client tokens for the active telephony drivers.\n\n```\nvar notify = new sn_notify.NotifyScoped();\nvar now_GR = new GlideRecord('sys_user');\nif (now_GR.get(gs.getUserID())) {\n  gs.info(notify.getTokens(now_GR));\n}\n```\n\nOutput:\n\n```\n{\"TwilioDirect\":\"eyJhxxxx.eyJleHAiOiIxxxx.7fejxxx_mbLxxx\"}\n```\n\n## NotifyScoped - getTokenTTL\\(String owner\\)\n\nReturns the maximum amount of time that a client session stays active for a specified telephony driver before automatically timing out.\n\n<table id=\"table_kym_hl2_1gb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nowner\n\n</td><td>\n\nString\n\n</td><td>\n\nName of the telephony driver for which to retrieve the session length. Valid values:\n\n-   Twilio: for the old driver\n-   TwilioDirect: for the new driver\n\n</td></tr></tbody>\n</table><table id=\"table_lym_hl2_1gb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nInteger\n\n</td><td>\n\nMaximum length of the session \\(in seconds\\). Default: 1800 seconds\n\n</td></tr></tbody>\n</table>The following example shows how to properly call this method and the associated response. It also shows what is returned if an invalid driver is passed.\n\n```\nvar owner = \"TwilioDirect\";  // Valid driver\nvar ttl = SNC.Notify.getTokenTTL(owner);\ngs.info(\"Token TTL for \" + owner + \" --> \" + ttl);\n \nowner = \"Abcxyz\";  // Invalid driver\nttl = SNC.Notify.getTokenTTL(owner);\n// For an invalid driver, we throw NoSuchNotifyDriverException saying that Abcxyzdriver is not available\n// and return the default value of TTL\ngs.info(\"Token TTL for \" + owner + \" --> \" + ttl); \n```\n\n## NotifyScoped - hasCapability\\(String notifyPhoneNumber, String capability\\)\n\nDetermines whether the specified phone number has the specified capability.\n\nThe telephony driver associated with the phone number contains a list of all of the capabilities of the phone.\n\n**Note:** In the base system, the Notify JS driver only has 'show\\_speakers' as a capability; this can be modified.\n\n|Name|Type|Description|\n|----|----|-----------|\n|notifyPhoneNumber|String|Phone number for which to check for the specified capability.|\n|capability|String|Capability to detect. The string text must be an exact match to what is in the phone.|\n\n<table id=\"table_c3l_2n2_1gb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the specified phone has the specified capability.-   true: phone has the capability\n-   false: phone does not have the capability\n\n</td></tr></tbody>\n</table>This example shows how to check if a phone has a specific capability.\n\n```\n// Each driver has a defined set of capabilities.\n\nvar capability = 'show_speakers';\ngs.info(sn_notify.NotifyScoped.hasCapability('+185xxxxxxxx', capability)); // true\n \ncapability = 'send_sms';\ngs.info(sn_notify.NotifyScoped.hasCapability('+185xxxxxxxx', capability)); // false\n```\n\n## NotifyScoped - kick\\(GlideRecord participant\\)\n\nRemoves the specified caller from the current Notify conference call.\n\n|Name|Type|Description|\n|----|----|-----------|\n|participant|GlideRecord|GlideRecord object containing the Notify Participant \\[notify\\_participant\\] record of the caller to remove from the conference call.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThis example shows how to remove a participant from a call.\n\n```\nvar participant = new GlideRecord('notify_participant');\nparticipant.get('<sys_id>');\nif (participant.isValid()) {\n    new sn_notify.NotifyScoped().kick(participant);\n}\n```\n\n## NotifyScoped - modifyCall\\(GlideRecord callRecord, NotifyAction notifyAction\\)\n\nPerforms one or more activities on an active Notify phone call.\n\nUse this method to change the behavior of a call. For example, transferring a call, playing audio, or forcing a hangup.\n\n**Note:** The scoped implementation of this method only supports custom Notify activities. Unlike the global implementation, it does not provide a NotifyAction API. For details on how to create a custom Notify activity, see [Notify workflow activities](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/c_NotifyActivities.md).\n\n|Name|Type|Description|\n|----|----|-----------|\n|callRecord|GlideRecord|Notify Call \\[notify\\_call\\] record of the call for which to apply the actions.|\n|notifyAction|NotifyAction|NotifyAction object describing one or more activities to perform on the call.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n## NotifyScoped - mute\\(GlideRecord participantRecord\\)\n\nMutes the specified conference call participant.\n\n|Name|Type|Description|\n|----|----|-----------|\n|participantRecord|GlideRecord|GlideRecord from the notify\\_participant table for the participant to mute.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how to mute a caller.\n\n```\nvar notifyParticipantGr = new GlideRecord('notify_participant');\nnotifyParticipantGr.get('active participant sys id');\n \nif (notifyParticipantGr.isValid) {\n    sn_notify.NotifyScoped.mute(notifyParticipantGr);\n}\n```\n\n## NotifyScoped - queueCall\\(GlideRecord callRecord\\)\n\nPuts the specified call into a queue \\(on hold\\).\n\nResume a queued call using the dequeueCall\\(\\) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|callRecord|GlideRecord|GlideRecord object of the Notify Call record \\(notify\\_call table\\) to put on hold.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar call = new GlideRecord('notify_call');\ncall.get('<call record sys_id>');\nif (call.isValid()) {\n    new sn_notify.NotifyScoped().queueCall(call);\n}\n```\n\n## NotifyScoped - sendBulkSMS\\(NotifyPhoneNumber notifyPhoneNumber, String toPhoneNumbers, String messageBody, GlideRecord source\\)\n\nSends a specified SMS message to the specified list of Notify clients \\(phone numbers\\).\n\n<table id=\"table_ss5_g1d_1gb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nnotifyPhoneNumber\n\n</td><td>\n\n[NotifyPhoneNumber](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/NPNScopedAPI.md)\n\n</td><td>\n\nPhone number from which the SMS message is being sent.\n\n</td></tr><tr><td>\n\ntoPhoneNumbers\n\n</td><td>\n\nString\n\n</td><td>\n\nComma separated list phone numbers to which to send the SMS message.Format: E.164-compliant\n\n</td></tr><tr><td>\n\nmessageBody\n\n</td><td>\n\nString\n\n</td><td>\n\nSMS text to send.\n\n</td></tr><tr><td>\n\nsource\n\n</td><td>\n\n[GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n\n</td><td>\n\nSource record that prompted this SMS message, such as an incident.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Null|\n\nThis example shows how to send an SMS message to multiple phone numbers \\(bulk SMS\\).\n\n```\nvar incidentGr = new GlideRecord('incident');\nincidentGr.get('active incident sys_id');\nif (incidentGr.isValid()) {\n    sn_notify.NotifyScoped.sendBulkSMS('+15413970605', ['+919885XXXXXX', '+919775XXXXXX'], 'Test automation message', incidentGr);\n}\n```\n\n## NotifyScoped - sendSMS\\(NotifyPhoneNumber notifyPhoneNumber, String toPhoneNumber, String messageBody, GlideRecord source\\)\n\nSends an SMS text message to an E.164-compliant phone number.\n\nThis method creates a new record on the Notify Message \\[notify\\_message\\] table and associates it with the source record.\n\n|Name|Type|Description|\n|----|----|-----------|\n|notifyPhoneNumber|[NotifyPhoneNumber](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/NPNScopedAPI.md)|Notify phone number or short code to which to send this SMS message.|\n|toPhoneNumber|String|E.164-compliant phone number to which to send the SMS message.|\n|messageBody|String|SMS text message.|\n|source|[GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)|Source record that prompted this SMS message, such as an incident.|\n\n|Type|Description|\n|----|-----------|\n|String|Unique message SID; stored in the Notify Message \\[notify\\_message\\] record as message\\_id.|\n\nThe following example shows how to send an SMS message.\n\n```\nvar incidentGr = new GlideRecord('incident');\nincidentGr.get('active incident sys_id');\nif (incidentGr.isValid()) {\n    sn_notify.NotifyScoped.sendSMS('+15413970605', '+919885XXXXXX', 'Test automation message', incidentGr);\n}\n```\n\n## NotifyScoped - unmute\\(GlideRecord participantRecord\\)\n\nUnmutes the specified conference call participant.\n\n|Name|Type|Description|\n|----|----|-----------|\n|participantRecord|GlideRecord|GlideRecord from the notify\\_participant table for the participant to unmute.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThis example shows how to unmute a specified call participant.\n\n```\nvar notifyParticipantGr = new GlideRecord('notify_participant');\nnotifyParticipantGr.get('active participant sys id');\n \nif (notifyParticipantGr.isValid) {\n    sn_notify.NotifyScoped.unmute(notifyParticipantGr);\n}\n```\n\n"}}