GlideDateTime.subtract doesn't work

abrouf
Kilo Sage

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());

21 REPLIES 21

Hi Gowrisaankar,


Yes I did, here is my due date info:


find_real_file.png


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();


        }


}


Hi Andrew,


Thank you for sharing your thought. I used this script like this - System Policy > Events > Script Actions>New. No luck.


find_real_file.png


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

Exactly that I want and I used calculated field option first but no luck