- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2016 06:56 AM
I am trying to use a business rule to auto calculate a duration field in that is used in a scoped application. I need the duration based on the difference of 2 date / time fields I tried to modify one that we are already using for Problem management but the gs.dateDiff is only available in global. Below is a copy of the current script being used as well as the error im currently getting.
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
gdt1 = current.u_incident_start.getGlideObject();
gdt2 = current.u_resolution_time.getGlideObject();
current.u_mttr = GlideDateTime.subtract(gdt1.getDisplayValue(),gdt2.getDisplayValue());
current.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2016 07:28 AM
Thanks Chuck, that got me close. I had to adjust to the following to make it work but I may have missed something in your original post.
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
current.u_mttr = GlideDateTime.subtract(new GlideDateTime(current.getValue("u_incident_start")), new GlideDateTime(current.getValue("u_resolution_time")));
current.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2016 07:02 AM
Forgot my reference to GlideDateTime.subtract()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2018 07:47 AM
In Scoped applications
Client Script
Script Include
Result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2019 05:38 PM
Thank you. this worked for me.