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.

How to set display value on date if the value is a string?

e_wilber
Tera Guru

I'm not sure how to better phrase this question.

 

I am trying to use isInSchedule and it's always showing false, which according to https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1001223, it's because I am passing a date into the GlideDateTime.

 

Since this is a script include that's just getting the date passed via this format, how do I set display value to get it in the correct format? startTime is receiving the date in format 10/30/2023 17:00:00.


var assignedTo = this.getParameter('sysparm_assigned_to');

var startTime = this.getParameter('sysparm_start'); // format: 10/30/2023 17:00:00
var glide = new GlideRecord('cmn_schedule');
var personalSchedule = new global.FSMMobileUtil().getUserSchedule(assignedTo);

 

var checkdate = new GlideDateTime(startTime);
checkdate.setDisplayValue(checkDate);
var sched = new GlideSchedule(glide.sys_id);

gs.log('is this in schedule? : ' + sched.isInSchedule(checkdate)); // ALWAYs returns false

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@e_wilber 

try this

var assignedTo = this.getParameter('sysparm_assigned_to');

var startTime = this.getParameter('sysparm_start'); // format: 10/30/2023 17:00:00
var personalSchedule = new global.FSMMobileUtil().getUserSchedule(assignedTo);


var checkdate = new GlideDateTime(startTime);
checkdate.setDisplayValue(startTime, 'MM/dd/yyyy HH:mm:ss'); // use the format while setting
var sched = new GlideSchedule('scheduleSysId'); // pass schedule sysId here

gs.log('is this in schedule? : ' + sched.isInSchedule(checkdate)); // ALWAYs returns false

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

I did try this and it's always returning false regardless of whether or it it's actually within their schedule.

 

I am printing out the discovered schedule and assigned to along with the date and all the values are correct, it's just failing.