The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Add an hour to time field in incident form

sagarpundir
Tera Contributor

i am trying to add an extra hour in time in time field but i face some problem .

this is my code running on before update 

 

(function executeRule(current, previous /*null when async*/) {

    var gt = new GlideTime(current.u_customtime);  
    var newTime = gt.addSeconds(300);  
    current.setValue('u_customtime', newTime);

})(current, previous);
6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@sagarpundir 

syntax is different, this should work fine

1) you should use GlideDateTime

2) addSeconds() doesn't return anything

(function executeRule(current, previous /*null when async*/ ) {

    var gt = new GlideDateTime(current.u_customtime);
    gt.addSeconds(3600); // 1 hour is 3600 seconds
    current.setValue('u_customtime', newTime.getValue());

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@sagarpundir 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader