How to set display value on date if the value is a string?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 06:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 06:16 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 06:42 AM
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.