Error using new GlideDateTime.subtract()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 06:40 AM
I am trying to use the following code to get the duration between when the record was created and NOW (to get open-to-resolve duration).
(function executeRule(current, previous /*null when async*/) {
current.u_time_to_resolve = new GlideDateTime.subtract(current.sys_created_on, new GlideDateTime().getDisplayValue());
})(current, previous);
I am getting this error when running this business rule though. Any idea what is happening? This is a scoped app.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 06:46 AM
Update as is:
current.u_time_to_resolve = new GlideDuration(GlideDateTime.subtract(current.sys_created_on, new GlideDateTime().getDisplayValue()));
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 06:48 AM
Hello, the script throws an error because you trying to subtract glide object from string.
GlideDateTime.subtract expects 2 GlideDateTime parameters
try to follow the example below.
var gdt1 = new GlideDateTime("2011-08-28 09:00:00");
var gdt2 = new GlideDateTime("2011-08-31 08:00:00");
var dur = GlideDateTime.subtract(gdt1, gdt2); // Difference between gdt1 and gdt2
gs.info(dur.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 06:52 AM
Which of my paramaters would be considered a string?
sys_created_on should be a date and time, and newGlideDateTime should be the same thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2022 07:05 AM
new GlideDateTime().getDisplayValue() is consider a string . you can intialise gdt1 and gdt2 with a string
var gdt1 = new GlideDateTime(new GlideDateTime().getDisplayValue());
var gdt2 = new GlideDateTime(current.sys_created_on.getDisplayValue());
var dur = GlideDateTime.subtract(gdt1,
gdt2); // Difference between gdt1 and gdt2