How to add current time + extra time on ATF script

Naveen87
Tera Guru

Hey Developer,

I need to write a script to add 3minutes to current time & set these values on Planned state date on change request form.

 

Ex:- current time + 3minutes & then set this value to Planned start date on change record via ATF script.

 

Please suggest.

 

Thank you

1 REPLY 1

DUGGI
Giga Guru

@Naveen87 

 

you can use ServiceNow's GlideDateTime API to achieve this. Here's an example script to add 3 minutes to the current time and set the result to the "Planned start date" field on a change request form:

// Get the current time
var currentTime = new GlideDateTime();

// Add 3 minutes
currentTime.addMinutes(3);

// Set the value on the Planned start date field
var changeRequest = new GlideRecord('change_request');
changeRequest.addQuery('sys_id', current.sys_id); // Replace current with the sys_id of the current change request
changeRequest.query();

if (changeRequest.next()) {
  changeRequest.setValue('start_date', currentTime);
  changeRequest.update();
}