GlideDateTime.subtract doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2017 05:58 PM
I used the following commands on default value to calculate the number of days subtracting current date to due date but didn't work. Any comment or advise is greatly appreciated.
javascript:calendar_duration = GlideDateTime.subtract(due_date.getDisplayValue(), gs.nowDateTime());
Following this syntax:
<duration_field> = GlideDateTime.subtract(<start_field>.getDisplayValue(),gs.nowDateTime());
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 09:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 07:50 AM
this script works on the server:
var gr = new GlideRecord("problem");
if (gr.get('the_sys_id')){ // replace with actual sys_id
if (gr.due_date){
var start = new GlideDateTime(gr.due_date); //due date field value
var end = new GlideDateTime();
var dur = GlideDateTime.subtract(start, end); // returns a GlideDuration object
gr.calendar_duration = dur; //setting the duration field
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 10:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 10:36 AM
What are you actually trying to achieve??
If you want that field to be populated with the duration you can actually use a calculated field.
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 10:40 AM
Exactly that I want and I used calculated field option first but no luck