Glide duration for subtract is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 08:26 AM
Hi Team,
I have an issue with glide duration in the change form
When I was subtracting two duration fields, I got output has undefined value.
Could you please help me out where my script was not working.
script
--------
Script: 1 00:00:05 10:00:00 undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 08:42 AM
Are any of these field types duration or all date/time? There are different approaches to subtracting two actual duration fields vs date/time difference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 08:45 AM
Hi Brad,
In the script start_date and end_date are the date/time type fields remaining are duration type fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2024 10:53 AM
The issue is that you are attempting to subtract the value of two duration fields that were added together from the value of two date/time fields that were subtracted. One approach is to convert all fields to a numeric value, then add/subtract with ease, converting the final number to whatever format you need:
var a = new GlideRecord("change_request");
a.addEncodedQuery("numberSTARTSWITHCHG0030008");
a.query();
if (a.next()) {
var vdt = a.u_validationtime.dateNumericValue();
var back = a.u_backouttime.dateNumericValue();
var start = new GlideDateTime(a.start_date).getNumericValue();
var end = new GlideDateTime(a.end_date).getNumericValue();
var imp = end - start;
var add = vdt + back;
var sub = imp - add;
gs.print(imp + " " + add + " " + sub);
}