logo

NJP

Adding Custom "Timezone source" in SLA Definition

Import · Nov 09, 2021 · article

The calculation of SLA is dependent on various SLA Definition settings when you configure. One of them is "Timezone Source". Here I am taking a scenario that can be an use case where the need of Timezone source is very important.

Scenario#1

A Group consisting of Members from USA & India. An Incident has been assigned to this group. Ideally the SLA should calculate based on the Assignee's timezone because the resolution needs to be done by the Assignee and some members working in EST hours & some are working in IST hours. Going with the default Timezone source may not work in this scenario. You need to create a custom source for it.

image

Here is how you can create a custom timezone source

1. Go to the Dictionary entry of "Timezone source"

2. Add a choice as shown below

image

3. Go to the OOTB Script include called "SLATimezone" (Note: You can modify this script even though it is OOTB as modification of this script include is allowed as per comments from Servicenow)

image

Now, add the code like this

SLATimezone.source = function(source, /* task_sla */ gr, taskGr) {
    if (!taskGr || taskGr.sys_id.nil())
        taskGr = gr.task.getRefRecord();

    switch(source) {
        // The caller's time zone
        case 'task.caller_id.time_zone':
            return (SLATimezone._getCaller(taskGr)).time_zone;
        // The SLA definition's time zone
        case 'sla.timezone':
            return gr.sla.timezone;
        // The CI's location's time zone
        case 'task.cmdb_ci.location.time_zone':
            return taskGr.cmdb_ci.location.time_zone;
        // The task's location's time zone
        case 'task.location.time_zone':
            return taskGr.location.time_zone;
        // The caller's location's time zone (old and new property values)
        case 'task.caller_id.location.u_time_zone':
        case 'task.caller_id.location.time_zone':
            return (SLATimezone._getCaller(taskGr)).location.time_zone;
        case 'task.assigned_to.time_zone':
            return taskGr.assigned_to.time_zone;
        // (add your own ideas here)
        default:
            return null;
    }
};

4. You are all set to use this source now.

image

Let me know if any further information is needed.

Thanks,

Narsing

View original source

https://www.servicenow.com/community/itsm-articles/adding-custom-quot-timezone-source-quot-in-sla-definition/ta-p/2300946