OnCallContactPreferenceUtil - Global

concept brazil Updated Sep 10, 2026 5 min read c_OnCallContactPreferenceUtilAPI.md
Raw file servicenow.com

The OnCallContactPreferenceUtil script include provides methods for handling contact preferences.

For contact preference configuration, see Configure contact preferences.

This script include supports the OnCallRotation script include.

Parent Topic:Server API reference

OnCallContactPreferenceUtil - OnCallContactPreferenceUtil()

Creates an instance of the OnCallContactPreferenceUtil class.

Name Type Description
None

OnCallContactPreferenceUtil - getContactsAtByEscalatee(Object escalatee, Number contactAttempt, GlideDateTime gdt, String rotaSysIds)

Gets a list of contacts with the escalatee object. Each returned contact contains a list of user contact preferences.

Name

Type

Description

escalatee

Object

Mandatory. Escalatee object returned by the getEscalationPlan() method.

contactAttempt

Number

Optional. The attempt you are trying to contact [ default value = 1 ].- 1: First attempt

  • 2: First reminder
  • 3 or more: Subsequent reminders

gdt

GlideDateTime

Optional. yyyy-MM-dd HH:mm:ss format in the UTC timezone. Default is now.admin

rotaSysIds

String

Optional. Comma-separated string of Sys IDs of shifts from the [cmn_rota] table. Default value returns Sys IDs of the shifts at current time.

Type

Description

Array object

Array of escalatees (either a user, group, or device records depending on the notification rules) at a specific time and position.- type: String. Type of contact, e.g., user.

  • sys_id: String. Sys ID of the user from the [sys_user] table.
  • rota_id: String. Sys ID of the shift from the [cmn_rota] table.
  • roster_id: String. Sys ID of the roster from the [cmn_rota_roster] table.
  • escalation_step_id: String. If an escalation path has been defined, Sys ID of the escalation step from the [cmn_rota_esc_step_def] table.
  • forced_communication_channel: String. If specified in the preferences, mandatory communication channel. Supported values include SMS, voice or email.
  • override_user_contact_preference: Boolean. True if there are contact overrides, false otherwise.
  • preference_source: String. Source of preference, such as contact or group.
  • contact_attempt: Number. Contact attempts: 1 = first attempt, 2 = first reminder, and so on.
  • user_preferences: Array Object.
    • type: String. User's preferred contact format, e.g. sms, email, or number.
    • <name of preferred format, e.g., email or number>: String. Content of preferred contact type, e.g., email address or phone number.
  • contact_preferences, Array Object.
    • type: String. User's preferred contact format, e.g., email or number.
    • <name of preferred format, e.g., email or number>: String. Content of preferred contact type, e.g., email address or phone number.
``` var serviceDeskSysId = ''; var ocRotation = new OnCallRotation(); var escalationPlan = ocRotation.getEscalationPlan(serviceDeskSysId); var escalatee = escalationPlan[0];

var onContactPrefUtil = new OnCallContactPreferenceUtil(); var contactAttempt = 1; var gdt = new GlideDateTime(); var contacts = onContactPrefUtil.getContactsAtByEscalatee(escalatee, contactAttempt, gdt); gs.log(JSON.stringify(contacts));

Text
Output:

[{ "type": "user", "sys_id": "<Sys_ID>", "rota_id": "<Rotation_ID>", "roster_id": "", "escalation_step_id": "<Escalation_Step_ID>", "forced_communication_channel": "", "override_user_contact_preference": true, "preference_source": "contact", "contact_attempt": 1, "user_preferences": [{ "type": "sms", "number": "8587200477" }], "contact_preferences": [{ "type": "voice", "number": "5555555555" }] }]

Text
## OnCallContactPreferenceUtil - getUserPreferences\(String userSysId, Number contactAttempt, GlideDateTime gdt, String communicationTypes\)
Gets the list of contact preferences at the time at which the user has opted for communication. If no time is specified, then current time is used. This method is applicable to single and overlapping shifts.
<table id="table_ixr_4jk_3gb" class="parameters"><thead><tr><th>
Name
</th><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
userSysId
</td><td>
String
</td><td>
Sys ID of the user from the \[sys\_user\] table.
</td></tr><tr><td>
contactAttempt
</td><td>
Number
</td><td>
Optional. The attempt you are trying to contact \[ default value = 1 \].-   `1`: First attempt-   `2`: First reminder-   `3 or more`: Subsequent reminders
</td></tr><tr><td>
gdt
</td><td>
GlideDateTime
</td><td>
Optional. yyyy-MM-dd HH:mm:ss format in the UTC timezone. Default is now.
</td></tr><tr><td>
communicationTypes
</td><td>
String
</td><td>
Optional. Comma-separated string containing one or more of the following values:-   email-   sms-   voice
Default includes all available communication types.
</td></tr></tbody></table><table id="table_ubq_ykk_3gb" class="returns"><thead><tr><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
Array Object
</td><td>
On-call user contact preference. -   type: String. User's preferred contact format, e.g. sms, email, or number.-   &lt;name of preferred format, e.g., email or number&gt;: String. Content of preferred contact type, e.g., email address or phone number.
</td></tr></tbody></table>```var onContactPrefUtil = new OnCallContactPreferenceUtil();var contactAttempt = 1;var gdt = new GlideDateTime();var itilUserSysId = '<itilUserSysId>;var userPreferences = onContactPrefUtil.getUserPreferences(itilUserSysId, contactAttempt, gdt);gs.log(JSON.stringify(userPreferences));

Output:

JSON
[{    "type": "sms",    "number": "5555555555"}, {    "type": "voice",    "number": "5555555555"}]

OnCallContactPreferenceUtil - getCatchAllContacts(String rotaId, GlideDateTime gdt)

Gets a list of catch-all contacts and preferences.

Name Type Description
rotaId String Sys ID of the shift from the [cmn_rota] table.
gdt GlideDateTime Optional. yyyy-MM-dd HH:mm:ss format in the UTC timezone. Default is now.

Type

Description

Array object

List of catch-all contacts with preferences.- type: String. Type of contact, e.g., user.

  • sys_id: String. Sys ID of the user from the [sys_user] table.
  • rota_id: String. Sys ID of the shift from the [cmn_rota] table.
  • roster_id: String. Sys ID of the roster from the [cmn_rota_roster] table.
  • escalation_step_id: String. If an escalation path has been defined, Sys ID of the escalation step from the [cmn_rota_esc_step_def] table.
  • forced_communication_channel: String. If specified in the preferences, mandatory communication channel. Supported values include SMS, voice or email.
  • override_user_contact_preference: Boolean. True if there are contact overrides, false otherwise.
  • preference_source: String. Source of preference, such as contact or group.
  • contact_attempt: Number. Contact attempts: 1 = first attempt, 2 = first reminder, and so on.
  • user_preferences: Array Object.
    • type: String. User's preferred contact format, e.g. sms, email, or number.
    • <name of preferred format, e.g., email or number>: String. Content of preferred contact type, e.g., email address or phone number.
  • contact_preferences, Array Object.
    • type: String. User's preferred contact format, e.g., email or number.
    • <name of preferred format, e.g., email or number>: String. Content of preferred contact type, e.g., email address or phone number.
Example:
JavaScript
var onContactPrefUtil = new OnCallContactPreferenceUtil();var contactAttempt = 1;var gdt = new GlideDateTime();var rotaSysId = '<Rotation_Sys_ID>';var catchAllContacts = onContactPrefUtil.getCatchAllContacts(rotaSysId, gdt);gs.log(JSON.stringify(catchAllContacts));

Output:

JSON
[{    "type": "user",    "sys_id": "<Sys_ID>",    "rota_id": "<Rotation_ID>",    "roster_id": "",    "escalation_step_id": "<Escalation_Step_ID>",    "forced_communication_channel": "",    "override_user_contact_preference": true,    "preference_source": "contact",    "contact_attempt": 1,    "user_preferences": [{        "type": "sms",        "number": "8587200477"    }],    "contact_preferences": [{        "type": "voice",        "number": "5555555555"    }]}]
Search documentation
Search document titles and file paths on the brazil branch