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
01-27-2020 02:16 AM
I am facing same issue, 5 Feb 2020 returning 6 while it is Wednesday, I have run in background script and its same as on form while selecting Date of CR,
var firstDT = '2011-02-05 12:00:00'; // Date-Time Field
var day = GlideDateTime();
day.setValue(firstDT);
var dayofweek = day.getDayOfWeekLocalTime();
gs.print('Hello' + dayofweek);
Actual Code:
//Returns the Day of Week
getDayOfWeek: function(){
var firstDT = this.getParameter('sysparm_locID'); // Date-Time Field
var day = GlideDateTime();
day.setValue(firstDT);
var dayofweek = day.getDayOfWeekLocalTime();
return dayofweek;
}
Please let me know.