- 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-17-2020 02:53 AM
Hi,
What is the business requirement for this or what are you trying to achieve. It would be helpful if you could elaborate more on the requirement so that we can come up with a different solution.
Thanks
Sourav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â11-17-2020 03:04 AM
Thanks,
I have a number of different room booking forms and need to set the priority based on the meeting date.
Form 1 - If within 3 working days = P1
Form 2 - If today = P1, if within 5 working days = P2, if within 2 working days = P2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â11-17-2020 05:33 AM
Hi,
You can try it with a server side code like with a business rule. In that way if you fetch the value using the getValue() method it will return in the correct format and then you can apply your logic accordingly.
Thanks
Sourav
- 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:47 AM
Thanks for your input. This requirement has now been parked and i hope to pick it back up in a month or so.