GlideDateTime getDayofWeek resulting incorrect day
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2019 09:56 PM
Hi,
I have a requirement to set auto-populate CAB date based on Planned Start date. CAB meeting occurs usually every week Wednesday 2 p.m. I am writing a business rule for this and using GlideDateTime functions in the code.
I am using getDayofWeekLocalTime() function of Planned start date. this function returns integer value (1 for Monday, 2 for Tuesday,.....7 for Sunday). The script is working fine but at times fiving me wrong output.
I had used logs in my script and observed that this function is picking wrong day of the week intermittently. Due to this, cab date is set incorrectly. For example, if planned start is 3rd Sep 2019 (Tuesday), but if its identified as a Monday by the script, then cab date will be auto-populated as 29th Sep (Thursday ) whereas it should have been set as 28th Sep (Wednesday).
Has anyone faced similar issues while using GlideDateTime functions on Server side code. I cannot identify what could be possible reason for this.
- Labels:
-
Best Practices
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2019 10:17 PM
I have never faced any such issue. Can you post the script you are using to set the CAB date
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2019 10:18 PM
Hello Tina,
Generally, getDayofWeekLocalTime() returns the day of the week in the user's timezone. So for the CRs which you are facing the value, could you check the user's timezone and maybe you can find something to debug.
Mark my comment as a correct answer and helpful if it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2019 11:08 PM
Hey Tina, You can help via this code. You can write 'after' business rule,
(function executeRule(current, previous /*null when async*/) {
//Purpose - A calculation of the day of the week based on the Date of Loss field.
var dateOfLoss = new GlideDateTime(current.date_of_loss);
var dayNo= dateOfLoss.getDayOfWeekUTC();
switch(dayNo){
case 1 : current.day = 'Monday';
break;
case 2 : current.day = 'Tuesday';
break;
case 3 : current.day = 'Wednesday';
break;
case 4 : current.day = 'Thrusday';
break;
case 5 : current.day = 'Friday';
break;
case 6 : current.day = 'Saturday';
break;
case 7 : current.day = 'Sunday';
break;
default: current.day = '';
}
current.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2019 11:13 PM
Hi,
refer below link. it may help you
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GDT-getDayOfWeek