GlideDateTime.subtract

Vikram3
Giga Guru

Hello,

(function executeRule(current, previous /*null when async*/ ) {
    var responseSLA;
    var resolutionSLA;
    var resCheck;
    var resoCheck;
    var durCheck;
    var slaCheck = new GlideRecord('task_sla');
    slaCheck.addQuery('task', current.sys_id);
    slaCheck.query();
    while (slaCheck.next()) {
        if (slaCheck.task.assignment_group.name.includes('Supply')) {
            if (slaCheck.sla == 'c791bb61dbd658508a7cd0b2ca961906') {
                responseSLA = slaCheck.start_time.getDisplayValue();
            }
            if (slaCheck.sla == '7ea3bba1dbd658508a7cd0b2ca9619ac' && slaCheck.stage == 'completed') {
                resolutionSLA = slaCheck.end_time.getDisplayValue();                
            }
			calcTime();
        }
        if (slaCheck.task.assignment_group.name.includes('AOG')) {
            if (slaCheck.sla == '4858c35fdb9b50508a7cd0b2ca9619df') {
                responseSLA = slaCheck.start_time.getDisplayValue();
            }
            if (slaCheck.sla == '6d48835fdb9b50508a7cd0b2ca961950' && slaCheck.stage == 'completed') {
                resolutionSLA = slaCheck.end_time.getDisplayValue();
            }
			calcTime();
        }
    }

    function calcTime() {
        resCheck = GlideDateTime(responseSLA);
        resoCheck = GlideDateTime(resolutionSLA);
        durCheck = GlideDateTime.subtract(resCheck, resoCheck);
        var finalTime = new GlideDuration(durCheck);
        current.u_supplychain_calc = finalTime;
    }
	//current.update();
})(current, previous);

Above code will do subtraction of start and end date of two sla when it is completed. I want to subtract pause duration value from "finalTime" value. FYI, pause value is a duration field from task_sla. Can anyone assist on this.

1 ACCEPTED SOLUTION

Vikram3
Giga Guru

This got resolved by getting pause time as below

pauseDuration = slaCheck.pause_duration.dateNumericValue();

and after that,

durCheck = GlideDateTime.subtract(resCheck, resoCheck).getNumericValue();
var subTime = durCheck - pauseDuration;
var finalTime = current.u_supplychain_calc.setDateNumericValue(subTime);

View solution in original post

27 REPLIES 27

Just to make sure, is the script suppose to change what's going to be displayed in the form or update the value in the table?

In a nutshell, I have two sla's for case one is Response and another is resolution.

When a case is resolved, I need to subtract response start time and resolution end time and put it on the duration field. If pause duration is available I need to subtract that value too. This is a scoped app.

Vikram3
Giga Guru

This got resolved by getting pause time as below

pauseDuration = slaCheck.pause_duration.dateNumericValue();

and after that,

durCheck = GlideDateTime.subtract(resCheck, resoCheck).getNumericValue();
var subTime = durCheck - pauseDuration;
var finalTime = current.u_supplychain_calc.setDateNumericValue(subTime);