- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2020 01:28 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-07-2020 09:37 PM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 05:48 AM
What's happening? Is there any error message?
If the static value is not being set, the problem is with something else and not with the GlideDateTime/GlideDuration subtraction.
I think the original question on subtraction is working OK. There's another problem with value not being updated. Is this an insert business rule?
Is the if condition being executed? Insert some "gs.info()" statements to make sure one of the if condition is executed.
There's also if condition comparing with sys_id. Are these being executed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 06:01 AM
Yes it's a display BR. Why I chose display BR rather than after update is, "End Time" from task_sla is not throwing values. Hence I chose display BR and it is working fine when two values are subtracted using GlideDateTime.subtract. Now I want to subtract the pause duration from task_sla. Info messages are generated properly. when i put info messages on subtraction of pause duration it throws the above error.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 06:16 AM
Display business rule is executed before displaying a form. If the script is suppose to be executed after submission, should be using after update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 06:24 AM
When I chose after update, I am not getting below value.
resolutionSLA = slaCheck.end_time.getDisplayValue();
but when I use display BR, it works.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2020 06:35 AM
Is .end_time a custom field because I can't find it in task_sla table. What is the data type?