{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1083,"path":"api-reference/server-api-reference/c_OnCallContactPreferenceUtilAPI.md","title":"OnCallContactPreferenceUtil - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# OnCallContactPreferenceUtil- Global\n\nThe OnCallContactPreferenceUtil script include provides methods for handling contact preferences.\n\nFor contact preference configuration, see [Configure contact preferences](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/it-service-management/config-my-contact-prefs-oncall.md).\n\nThis script include supports the [OnCallRotation](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_OnCallRotationAPI.md) script include.\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## OnCallContactPreferenceUtil - OnCallContactPreferenceUtil\\(\\)\n\nCreates an instance of the OnCallContactPreferenceUtil class.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n## OnCallContactPreferenceUtil - getContactsAtByEscalatee\\(Object escalatee, Number contactAttempt, GlideDateTime gdt, String rotaSysIds\\)\n\nGets a list of contacts with the escalatee object. Each returned contact contains a list of user contact preferences.\n\n<table id=\"table_o1s_x5j_3gb\" 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\nescalatee\n\n</td><td>\n\nObject\n\n</td><td>\n\nMandatory. Escalatee object returned by the [getEscalationPlan\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_OnCallRotationAPI.md) method.\n\n</td></tr><tr><td>\n\ncontactAttempt\n\n</td><td>\n\nNumber\n\n</td><td>\n\nOptional. The attempt you are trying to contact \\[ default value = 1 \\].-   `1`: First attempt\n-   `2`: First reminder\n-   `3 or more`: Subsequent reminders\n\n</td></tr><tr><td>\n\ngdt\n\n</td><td>\n\nGlideDateTime\n\n</td><td>\n\nOptional. yyyy-MM-dd HH:mm:ss format in the UTC timezone. Default is now.admin\n\n</td></tr><tr><td>\n\nrotaSysIds\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated string of Sys IDs of shifts from the \\[cmn\\_rota\\] table. Default value returns Sys IDs of the shifts at current time.\n\n</td></tr></tbody>\n</table><table id=\"table_nmd_wvj_3gb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nArray object\n\n</td><td>\n\nArray 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.\n-   sys\\_id: String. Sys ID of the user from the \\[sys\\_user\\] table.\n-   rota\\_id: String. Sys ID of the shift from the \\[cmn\\_rota\\] table.\n-   roster\\_id: String. Sys ID of the roster from the \\[cmn\\_rota\\_roster\\] table.\n-   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.\n-   forced\\_communication\\_channel: String. If specified in the preferences, mandatory communication channel. Supported values include SMS, voice or email.\n-   override\\_user\\_contact\\_preference: Boolean. True if there are contact overrides, false otherwise.\n-   preference\\_source: String. Source of preference, such as contact or group.\n-   contact\\_attempt: Number. Contact attempts: 1 = first attempt, 2 = first reminder, and so on.\n-   user\\_preferences: Array Object.\n    -   type: String. User's preferred contact format, e.g. sms, email, or number.\n    -   &lt;name of preferred format, e.g., email or number&gt;: String. Content of preferred contact type, e.g., email address or phone number.\n-   contact\\_preferences, Array Object.\n    -   type: String. User's preferred contact format, e.g., email or number.\n    -   &lt;name of preferred format, e.g., email or number&gt;: String. Content of preferred contact type, e.g., email address or phone number.\n\n</td></tr></tbody>\n</table>```\nvar serviceDeskSysId = '<Sys_ID>';\nvar ocRotation = new OnCallRotation();\nvar escalationPlan = ocRotation.getEscalationPlan(serviceDeskSysId);\nvar escalatee = escalationPlan[0];\n\nvar onContactPrefUtil = new OnCallContactPreferenceUtil();\nvar contactAttempt = 1;\nvar gdt = new GlideDateTime();\nvar contacts = onContactPrefUtil.getContactsAtByEscalatee(escalatee, contactAttempt, gdt);\ngs.log(JSON.stringify(contacts));\n```\n\nOutput:\n\n```\n[{\n    \"type\": \"user\",\n    \"sys_id\": \"<Sys_ID>\",\n    \"rota_id\": \"<Rotation_ID>\",\n    \"roster_id\": \"\",\n    \"escalation_step_id\": \"<Escalation_Step_ID>\",\n    \"forced_communication_channel\": \"\",\n    \"override_user_contact_preference\": true,\n    \"preference_source\": \"contact\",\n    \"contact_attempt\": 1,\n    \"user_preferences\": [{\n        \"type\": \"sms\",\n        \"number\": \"8587200477\"\n    }],\n    \"contact_preferences\": [{\n        \"type\": \"voice\",\n        \"number\": \"5555555555\"\n    }]\n}]\n```\n\n## OnCallContactPreferenceUtil - getUserPreferences\\(String userSysId, Number contactAttempt, GlideDateTime gdt, String communicationTypes\\)\n\nGets 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.\n\n<table id=\"table_ixr_4jk_3gb\" 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\nuserSysId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys ID of the user from the \\[sys\\_user\\] table.\n\n</td></tr><tr><td>\n\ncontactAttempt\n\n</td><td>\n\nNumber\n\n</td><td>\n\nOptional. The attempt you are trying to contact \\[ default value = 1 \\].-   `1`: First attempt\n-   `2`: First reminder\n-   `3 or more`: Subsequent reminders\n\n</td></tr><tr><td>\n\ngdt\n\n</td><td>\n\nGlideDateTime\n\n</td><td>\n\nOptional. yyyy-MM-dd HH:mm:ss format in the UTC timezone. Default is now.\n\n</td></tr><tr><td>\n\ncommunicationTypes\n\n</td><td>\n\nString\n\n</td><td>\n\nOptional. Comma-separated string containing one or more of the following values:-   email\n-   sms\n-   voice\n\nDefault includes all available communication types.\n\n</td></tr></tbody>\n</table><table id=\"table_ubq_ykk_3gb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nArray Object\n\n</td><td>\n\nOn-call user contact preference. -   type: String. User's preferred contact format, e.g. sms, email, or number.\n-   &lt;name of preferred format, e.g., email or number&gt;: String. Content of preferred contact type, e.g., email address or phone number.\n\n</td></tr></tbody>\n</table>```\nvar onContactPrefUtil = new OnCallContactPreferenceUtil();\nvar contactAttempt = 1;\nvar gdt = new GlideDateTime();\nvar itilUserSysId = '<itilUserSysId>;\nvar userPreferences = onContactPrefUtil.getUserPreferences(itilUserSysId, contactAttempt, gdt);\ngs.log(JSON.stringify(userPreferences));\n```\n\nOutput:\n\n```\n[{\n    \"type\": \"sms\",\n    \"number\": \"5555555555\"\n}, {\n    \"type\": \"voice\",\n    \"number\": \"5555555555\"\n}]\n```\n\n## OnCallContactPreferenceUtil - getCatchAllContacts\\(String rotaId, GlideDateTime gdt\\)\n\nGets a list of catch-all contacts and preferences.\n\n|Name|Type|Description|\n|----|----|-----------|\n|rotaId|String|Sys ID of the shift from the \\[cmn\\_rota\\] table.|\n|gdt|GlideDateTime|Optional. yyyy-MM-dd HH:mm:ss format in the UTC timezone. Default is now.|\n\n<table id=\"table_ygb_ypj_3gb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nArray object\n\n</td><td>\n\nList of catch-all contacts with preferences.-   type: String. Type of contact, e.g., user.\n-   sys\\_id: String. Sys ID of the user from the \\[sys\\_user\\] table.\n-   rota\\_id: String. Sys ID of the shift from the \\[cmn\\_rota\\] table.\n-   roster\\_id: String. Sys ID of the roster from the \\[cmn\\_rota\\_roster\\] table.\n-   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.\n-   forced\\_communication\\_channel: String. If specified in the preferences, mandatory communication channel. Supported values include SMS, voice or email.\n-   override\\_user\\_contact\\_preference: Boolean. True if there are contact overrides, false otherwise.\n-   preference\\_source: String. Source of preference, such as contact or group.\n-   contact\\_attempt: Number. Contact attempts: 1 = first attempt, 2 = first reminder, and so on.\n-   user\\_preferences: Array Object.\n    -   type: String. User's preferred contact format, e.g. sms, email, or number.\n    -   &lt;name of preferred format, e.g., email or number&gt;: String. Content of preferred contact type, e.g., email address or phone number.\n-   contact\\_preferences, Array Object.\n    -   type: String. User's preferred contact format, e.g., email or number.\n    -   &lt;name of preferred format, e.g., email or number&gt;: String. Content of preferred contact type, e.g., email address or phone number.\n\n</td></tr></tbody>\n</table>Example:\n\n```\n\nvar onContactPrefUtil = new OnCallContactPreferenceUtil();\nvar contactAttempt = 1;\nvar gdt = new GlideDateTime();\nvar rotaSysId = '<Rotation_Sys_ID>';\nvar catchAllContacts = onContactPrefUtil.getCatchAllContacts(rotaSysId, gdt);\ngs.log(JSON.stringify(catchAllContacts));\n```\n\nOutput:\n\n```\n[{\n    \"type\": \"user\",\n    \"sys_id\": \"<Sys_ID>\",\n    \"rota_id\": \"<Rotation_ID>\",\n    \"roster_id\": \"\",\n    \"escalation_step_id\": \"<Escalation_Step_ID>\",\n    \"forced_communication_channel\": \"\",\n    \"override_user_contact_preference\": true,\n    \"preference_source\": \"contact\",\n    \"contact_attempt\": 1,\n    \"user_preferences\": [{\n        \"type\": \"sms\",\n        \"number\": \"8587200477\"\n    }],\n    \"contact_preferences\": [{\n        \"type\": \"voice\",\n        \"number\": \"5555555555\"\n    }]\n}]\n```\n\n"}}