Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Add Time to a date/time field

Tapish Sharma1
Kilo Sage

Hi Folks, 

I am getting difference of two dates and the trying to add that to a date/time field, but with no luck . I am able to get the difference but that is not getting added to the field. Below is my code 

 

var cas1 = new GlideRecord('sn_customerservice_case');
cas1.get('db53532e47e251106b801c65d36d4307');
var resolved_at = new GlideDateTime(cas1.resolved_at);
var rejection = new GlideDateTime(cas1.u_rejection_time);

 

var dur2 = GlideDateTime.subtract(resolved_at,rejection);
var num_value = dur2.getNumericValue();

 

var sla = new GlideRecord('task_sla');
sla.addQuery('task',cas1.sys_id);
sla.query();
if(sla.next()){

var breach = new GlideDateTime(sla.planned_end_time);
var new_breach = breach.add(num_value);

gs.print(new_breach);

}

 

new_breach returns undefined 

 

1 ACCEPTED SOLUTION

Dan Ostler
Tera Guru

The add() method on GlideDateTime does not return a value, which is the reason why "new_breach" returns undefined. In this case, when you call the add() method against the "breach" variable it is mutating the value of "breach". I hope this helps!

View solution in original post

1 REPLY 1

Dan Ostler
Tera Guru

The add() method on GlideDateTime does not return a value, which is the reason why "new_breach" returns undefined. In this case, when you call the add() method against the "breach" variable it is mutating the value of "breach". I hope this helps!