- 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 06:52 AM
Hi Chad,
Following links should be helpful:
https://community.servicenow.com/community?id=community_question&sys_id=11010fa5db98dbc01dcaf3231f96194f
Following example:
var date1 = new GlideDateTime(current.degradation_start + ' 00:00:00');
var date2 = new GlideDateTime(current.degradation_stop + ' 00:00:00');
var dateDiff = GlideDateTime.subtract(date1,date2);
var durationStr = dateDiff.getDurationValue();
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â07-26-2018 07:59 AM
Even using your example, the field remains blank.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â07-26-2018 08:08 AM
What are the field types of degradation_start, degradation_stop, degradation_duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â07-26-2018 08:10 AM
Respectively-- Date/Time, Date/Time, Duration