- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â07-26-2018 06:45 AM
I'm used to calculating duration fields using dateDiff, but since that doesn't work in my scoped application, I'm having to use GlideDateTime.subtract, which I can't get to work on my business rule that is triggered when the start date or stop date changes. Can anyone tell me why this script isn't working as written? I get no errors, but the degradation_duration field just remains blank.
var start = new GlideDateTime(current.degradation_start.getDisplayValue());
var stop = new GlideDateTime(current.degradation_stop.getDisplayValue());
var duration = GlideDateTime.subtract(start, stop).getDisplayValue();
current.degradation_duration = duration.getDisplayValue();
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â07-26-2018 08:34 AM
You are almost there, only think is you need to take out the display value while setting to the duration. Use this code
var start = new GlideDateTime(current.degradation_start.getDisplayValue());
var stop = new GlideDateTime(current.degradation_stop.getDisplayValue());
var duration = GlideDateTime.subtract(start, stop);
current.degradation_duration = duration;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â07-26-2018 08:34 AM
You are almost there, only think is you need to take out the display value while setting to the duration. Use this code
var start = new GlideDateTime(current.degradation_start.getDisplayValue());
var stop = new GlideDateTime(current.degradation_stop.getDisplayValue());
var duration = GlideDateTime.subtract(start, stop);
current.degradation_duration = duration;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â07-26-2018 08:38 AM
Thanks, that seems to have done the trick.