GlideDateTime.subtract(GlideDateTime, GlideDateTime) is throwing an error?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 10:37 AM
Hello all,
I'm running into a small, but rather strange error today. While trying to design an algorithm in a Script Include reliant on dates, I have an if statement that checks if the difference between two dates is greater than a day:
var schedule = new GlideSchedule('My Schedule');
var curDate = new GlideDateTime();
var nextDate = new GlideDateTime();
while (//nextDate is not greater than a certain point in time) {
var nextDuration = schedule.whenNext();
var nextDate.add(nextDuration);
//My code changes nextDate and
if (nextDuration <= 600000 && nextDate.subtract(curDate, nextDate).getDayPart() < 1) { //Error occurs here.
//Add a certain time to nextDate.
continue;
}
}
(Please keep in mind the above code is not representational of my entire script for the sake of time.)
This Script Include is instantiated and called on by a Scheduled Script Execution that runs on the daily. In theory, this should work just fine - I define the GlideDateTime objects above, and then use one of them to get a GlideDuration object for comparison. However, I'm getting this error as a result:
InternalError: Can't find method
com.glide.glideobject.GlideDateTime.subtract(com.glide.script.fencing.ScopedGlideDateTime,com.glide.script.fencing.ScopedGlideDateTime).
(sys_script_include.4154861adb6123007b92f28239961999.script; line 225)
Do you folks have any clue what's going on? I checked the API and GlideDateTime.subtract is a part of the Scoped object, I tried instantiating another GlideDateTime object above the if statement and using it, and I also tried assigning nextDate.subtract to its own variable. This is just a really strange issue. It occurred after a period of time in the instance passed where logs were not being stored in the table, either.
Thank you for your time,
Vellv

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 10:44 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 10:59 AM
Hi Rahul,
This is what I'm getting from my application logs:
curDate: 2018-12-17 18:58:06; nextDate: 2018-12-17 18:58:07
The same error is still output after this point, however.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2018 11:11 AM
Hi,
I just checked, it is working fine as per provided time.
What is the value you are getting after adding duration ? a suggestion
var schedule = new GlideSchedule('My Schedule');
var curDate = new GlideDateTime();
var nextDate = new GlideDateTime();
while (//nextDate is not greater than a certain point in time) {
var nextDuration = schedule.whenNext();
var nextDate.add(nextDuration);
var nextDate2 = new GlideDateTime(nextDate);
if (nextDuration <= 600000 && nextDate.subtract(curDate, nextDate2).getDayPart() < 1) {
continue;
}
}