Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get Value of Schedule Entry start and end dates

travuswarren
Giga Contributor

Hello all,

I am attempting to retrieve the values of the start and end dates from a schedule entry to populate a change requests Planned start date and Planned End date fields.   I see that the two format types differ from Schedule Date/Time - Schedule Entry to Date/Time - Change Request, which may be causing me issues. The script log says that the value if start_date_time = 20160119T002000 as an example. Below is my business rule attempt but the values on the change record are currently null after an update.

function onAfter(current, previous) {

var gr = new GlideRecord('change_request');

  gr.addQuery('sys_id', current.u_change_number);

  gr.query();

  while(gr.next()){

  gr.start_date = current.start_date_time;

  gr.end_date = current.end_date_time;

  gr.update();

}

}

Thanks in advance.

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

  gr.start_date = current.start_date_time.getDisplayValue();  


gr.end_date = current.end_date_time.getDisplayValue();



try this



-Anurag

View solution in original post

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

  gr.start_date = current.start_date_time.getDisplayValue();  


gr.end_date = current.end_date_time.getDisplayValue();



try this



-Anurag

That was a quick win.



Thanks again for the quick response.


Anurag,  



I assume Travis configured this as:


find_real_file.png


if you run this in 2017, current.start_date_time.getDisplayValue() still returns 2016-01-19 dates. Any solution? Thanks.


This might result in wrong dates, for example 6th of January may be converted to 1th of June.


I believe this solution is more reliable:



          var day = new GlideDateTime();


          day.setValueUTC(gr.start_date_time,"yyyyMMdd");