javascript:gs.minutesAgoStart on Scheduled Job script

nogizaka46_jame
Kilo Contributor

I was trying to use a scheduled job to create a change ticket, if I want to set the work start / work end field to a specific time, what's the equivalent of javascript:gs.minutesAgoStart when I translate It to a script using the scheduled job? The thing is the I've already used the javascript:gs.daysAgoStart and javascript:gs.daysAgoEnd for the date using the template within the scheduled job. Or Is It much better if I use a full script for the date/time field for workstart/workend field of the change ticket?

Regards,

8 REPLIES 8

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello James,




For date field use gr.FIELDCOLUMNAME = gs.now(); //Here gr is the gliderecord object


For date/time field use gr.FIELDCOLUMNAME = gs.nowdatetime(); //Here gr is the gliderecord object



Sample:


var gr = new GlideRecord("sys_user");


if (gr.get(event.parm1.toString())) {


      // Do something based on the Password Changing


      gs.log("The user password changed so do something else...");


      gr.u_password_last_reset = gs.now();


      gr.update();


}



Reference:


http://wiki.servicenow.com/index.php?title=GlideSystem_Date_and_Time_Functions


chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Hi James,



If you want to set Work Start / Work End to specific time and that time is fixed then you can assign as a string also, for example :



gr.start_date = '2016-08-10 12:00:00';


gr.end_date = '2016-08-10 18:00:00';


gr.update();


Minor change. I've seen issues if we set the date directly. Instead, create a GlideDateTime object from a GlideDate object by passing in the GlideDate object as a parameter to the GlideDateTime constructor.



Sample code:



var gDate = new GlideDate();


gDate.setValue('2015-01-01');


gs.info(gDate);



var gDT = new GlideDateTime(gDate);


gs.info(gDT);


Thanks Pradeep, I was just only having a problem on setting the work start/end time field on the change ticket, for the date I've already set It on the template.