{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":858,"path":"api-reference/server-api-reference/OnCallContactPrefTemplateAPI.md","title":"OnCallContactPrefTemplate - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# OnCallContactPrefTemplate- Global\n\nThe OnCallContactPrefTemplate script include provides methods to apply contact preference templates to escalation sets.\n\nFor more information about the escalation process, see [Defining On-Call Scheduling escalation process](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/it-service-management/defining-escalation-process-and-template.md).\n\nThis script include requires the On-Call Scheduling plugin \\(com.snc.on\\_call\\_rotation\\).\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## OnCallContactPrefTemplate - OnCallContactPrefTemplate\\(\\)\n\nInstantiates an OnCallContactPrefTemplate object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| ||\n\nThis example instantiates an OnCallContactPrefTemplate object.\n\n```\nvar contactPrefTemp = new global.OnCallContactPrefTemplate();\n```\n\n## OnCallContactPrefTemplate - copyContactPreferences\\(String templateSysId, String escalationSetSysId\\)\n\nApplies a contact preference template to an escalation set.\n\nWhen the template is applied to the escalation set, contact attempt records are created in the Shift Contact Preference \\[cmn\\_rota\\_contact\\_preference\\] table.\n\nBefore calling this method, call the deleteContactPreferenceAttempts\\(\\) method to delete existing contact attempt records. If existing records are not deleted first, this method returns an error.\n\n|Name|Type|Description|\n|----|----|-----------|\n|templateSysId|String|Sys\\_id of the contact preference template in the On-Call Contact Preference Template \\[on\\_call\\_template\\_contact\\_preference\\] table.|\n|escalationSetSysId|String|Sys\\_id of the escalation set in the Shift Escalation Set \\[cmn\\_rota\\_escalation\\_set\\] table.|\n\n<table id=\"table_dgl_2rd_3xb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nObject containing error and warning messages. If the operation was successful, this object is empty.\n\n**Note:** If an error occurs, the operation stops and the template is not applied. If a warning occurs, the operation continues and some records are still created.\n\n ```\n{\n  \"error\": \"String\", \n  \"warning\": \"String\" \n}\n```\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.error\n\n</td><td>\n\nError message.Possible values:\n\n-   Contact preference template sys\\_id is not correct\n-   Escalation set sys\\_id is not correct\n-   Contact attempts exist already\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;Object&gt;.warning\n\n</td><td>\n\nWarning message.Data type: String\n\n</td></tr></tbody>\n</table>This example applies a contact preference template to the Service Desk – Default escalation set. The return object is empty because there are no errors or warnings.\n\n```\nvar escSetSysId = \"a47ac1abeb5a6110249e8d835d5228aa\";\nvar templateSysId = \"f8dac9ebeb5a6110249e8d835d522873\";\n\nvar contactPrefTemp = new global.OnCallContactPrefTemplate();\n\n// delete existing contact attempt records before applying the template\ncontactPrefTemp.deleteContactPreferenceAttempts(escSetSysId); \n\nvar result = contactPrefTemp.copyContactPreferences(templateSysId, escSetSysId);\ngs.info(JSON.stringify(result));\n```\n\nOutput:\n\n```\n{}\n```\n\n## OnCallContactPrefTemplate - deleteContactPreferenceAttempts\\(String escalationSetSysId\\)\n\nDeletes all contact preferences associated with an escalation set.\n\nAll contact attempt records for the escalation set are deleted from the Shift Contact Preference \\[cmn\\_rota\\_contact\\_preference\\] table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|escalationSetSysId|String|Sys\\_id of the escalation set in the Shift Escalation Set \\[cmn\\_rota\\_escalation\\_set\\] table.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example deletes all contact preferences associated with the Service Desk – Default escalation set.\n\n```\nvar escSetSysId = \"a47ac1abeb5a6110249e8d835d5228aa\";\nvar contactPrefTemp = new global.OnCallContactPrefTemplate();\n\ncontactPrefTemp.deleteContactPreferenceAttempts(escSetSysId);\n```\n\n"}}