- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â11-16-2020 09:39 AM
Hi all,
I have the following issue with getDayOfWeekLocalTime. If i pick the 5th December, its returning 2 (Tuesday) instead of a 6 (Saturday). It does seems to work fine if i change the date format in my user profile to yyyy-MM-dd.
Below is my script include. I'm basically taking a datetime input, checking if its a weekday against a schedule and then trying to print the day of the week.
var UserClientUtilities = Class.create();
UserClientUtilities.prototype = Object.extendsObject(AbstractAjaxProcessor, {
prioritySetter: function() {
var schedule = new GlideSchedule('7a5c6245db20e8907f8b6792ca961992'); //Catalog Item Priority Checker
var meetingDatetime = this.getParameter('sysparm_meeting_date_time');
var dateTime = new GlideDateTime(meetingDatetime);
var dateOnly = meetingDatetime.split(" ")[0];
var dayOfWeek = dateTime.getDayOfWeekLocalTime();
var isWeekday = "No";
if (schedule.isInSchedule(dateTime)) {
isWeekday = "Yes";
} else {
isWeekday = "No";
}
var answer = ("Current Meeting Date: " + dateOnly + " - " + "Weekday: " + isWeekday + " - " + "Day Selected: " + dayOfWeek);
return answer;
},
type: 'UserClientUtilities'
});
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â11-17-2020 04:09 AM
Seems due to format
Try this
var dt = '05/12/2020 09:03:34';
var gdt = new GlideDateTime();
gdt.setDisplayValue(dt,'dd/MM/yyyy HH:mm:ss');
gs.info(gdt.getDate());
var dayOfWeek = gdt.getDayOfWeekLocalTime();
gs.info(dayOfWeek);
Output:
So update your script like this
prioritySetter: function() {
var schedule = new GlideSchedule('7a5c6245db20e8907f8b6792ca961992'); //Catalog Item Priority Checker
var meetingDatetime = this.getParameter('sysparm_meeting_date_time');
var dateTime = new GlideDateTime();
dateTime.setDisplayValue(meetingDatetime,'dd/MM/yyyy HH:mm:ss');
var dateOnly = dateTime.getDate();
var dayOfWeek = dateTime.getDayOfWeekLocalTime();
var isWeekday = "No";
if (schedule.isInSchedule(dateTime)) {
isWeekday = "Yes";
} else {
isWeekday = "No";
}
var answer = ("Current Meeting Date: " + dateOnly + " - " + "Weekday: " + isWeekday + " - " + "Day Selected: " + dayOfWeek);
return answer;
},
Regards
Ankur
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-19-2020 07:55 AM
I believe your original question is answered with my comment by converting the format.
If my response helped please mark my response as correct and helpful.
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â01-05-2021 02:27 AM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
Thanks!
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader