GlideSchedule Add method cannot be found?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 12:44 PM
Below is the specific error I'm receiving.
I'm trying to add a duration to a date/time based on a schedule so that I can then find the actual duration between the new date/time and now to create a timer duration. (the oob timer setting to reference the duration field on the task_sla isn't working - it's not calculating the time correctly. I have one test sla that has been pending for over 3 hours and the duration it is supposed to wait is just 35 minutes).
I cannot see what is wrong with my below script that is causing servicenow to thing that the "add" method doesn't exist for GlideSchedule.
My log will grab the right current date/time, it also logs the correct duration (current.u_pause_timer.getDurationValue() logs 00:35:00). But when I get to sched.add(startTime,current.u_pause_timer.getDurationValue()), it throws an error.
Wait for remaining pause notification time(efb73ccb4f10e700709af7e18110c7a0): org.mozilla.javascript.WrappedException: Wrapped org.mozilla.javascript.EvaluatorException: Can't find method com.glide.schedules.Schedule.add(com.glide.glideobject.GlideDateTime,string). (// // Set 'answer' to the number of seconds this timer should wait
// var timeToWait = new GlideDuration(current.sla.u_pause_notification);
// gs.log('timeToWait: ' + timeToWait,'SLAPause');
// var remainingTimeToWait = timeToWait.subtract(current.business_pause_duration);
// gs.log('remainingTimeToWait: ' + remainingTimeToWait,'SLAPause');
// var durationSeconds = (remainingTimeToWait/1000);
// gs.log('workflow will now wait this many seconds: ' + durationSeconds,'SLAPause');
// answer = durationSeconds;
var startTime = new GlideDateTime();
var sched = new GlideSchedule(current.schedule.sys_id);
//var timeDur = new GlideDuration(current.u_pause_timer.getValue());
var timeDur = current.u_pause_timer;
gs.log('timeDur: ' + timeDur,'SLAPause');
//var testingTimeDur = new GlideDuration(60*60*24*1000*2);
//gs.log('testingTimeDur: ' + testingTimeDur.getDurationValue(),'SLAPause');
var endTime = sched.add(startTime,current.u_pause_timer.getDurationValue());
gs.log('endTime: ' + endTime,'SLAPause');
var dur = GlideDateTime.subtract(startTime,endTime);
gs.log('duration from gdt subtract: ' + dur,'SLAPause');
var durSec = dur/1000;
gs.log('duration seconds: ' + durSec,'SLAPause');
answer = durSec;; line 17) (<refname>; line 253)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 01:03 PM
try below add , and quotes
var endTime = sched.add(startTime,current.u_pause_timer.getDurationValue(), '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2018 09:22 AM
So, I have the script working... theoretically. All my logging shows that I'm returning the right seconds to wait (for testing, I've changed it to one minute, so the logging returns 60), but the timer isn't actually ever ending. It's just hanging there. And I cannot for the life of me figure out why. Current script:
// Set 'answer' to the number of seconds this timer should wait
var startTime = new GlideDateTime();
var schedToUse = new GlideSchedule();
var pauseTimer = new GlideDuration(current.u_pause_timer.getDurationValue());
schedToUse.load(current.schedule.sys_id);
var endTime = schedToUse.add(startTime,pauseTimer);
gs.log('EndTime: ' + endTime.getDisplayValue(),'SLAPause');
var dur = GlideDateTime.subtract(startTime,endTime);
var newTime = dur.getNumericValue();
gs.log('newTime in milliseconds ' + newTime,'SLAPause');
var durSec = newTime/1000;
gs.log('duration seconds: ' + durSec,'SLAPause');
answer = durSec;
The above logs 'duration seconds: 60'. But the workflow timer never ends.
I found another person that posted their solution and they fixed with a datediff, and tried this, but it fails to wait at all:
// Set 'answer' to the number of seconds this timer should wait
var startTime = new GlideDateTime();
var schedToUse = new GlideSchedule();
var pauseTimer = new GlideDuration(current.u_pause_timer.getDurationValue());
schedToUse.load(current.schedule.sys_id);
var endTime = schedToUse.add(startTime,pauseTimer);
answer = gs.dateDiff(startTime, endTime, true);
I have also tried just using the fields on the SLA, which also doesn't ever complete:
This is the sla record showing the fields the workflow timer references:
This is that timer's setting:
None of this is working and I honestly don't have a clue why.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-10-2018 01:03 AM
Hi kristenankeny,
The script below calculates a duration between two dates using schedule:
var schedule = new GlideSchedule('sched_sys_id');
var duration = schedule.duration(/*GlideDateTime object*/time1, /*GlideDateTime object*/time2).getByFormat('ddd HH:mm:ss');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2023 11:05 AM
Any luck on this? I am facing the issue while i am calling from scope application ...