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 07:23 AM
I am beginning to wonder if this just won't work in a scoped app.
I have updated to
var startDate = current.sys_created_on.getDisplayValue();
var endDate = new GlideDateTime(new GlideDateTime().getDisplayValue());
var dur = GlideDateTime.subtract(startDate, endDate);
gs.addInfoMessage(dur);
And now I'm getting an error
Error running business rule 'Record Time to Resolve' on sn_customerservice_customer_care: CS0001798, exception: org.mozilla.javascript.EvaluatorException: Can't find method com.glide.glideobject.GlideDateTime.subtract(string,com.glide.script.fencing.ScopedGlideDateTime). (sys_script.82d753881b7c91506fc6a8a8b04bcb9a.script; line 7)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 10:32 AM
Try using:
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar