- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2023 03:06 PM
I created a before BR in Change, and it's able to get to whatever the next Friday from the planned start date, but the time is always set to 6 PM instead of 9 AM. How can I set it to 9 AM? Here is my script in BR,
var getDay = new GlideDateTime(current.start_date);
var t = getDay.getDayOfWeekLocalTime();
if (t == 1) {
getDay.addDaysLocalTime(5);
current.cab_date = getDay.getDisplayValue();
} else if (t == 2) {
getDay.addDaysLocalTime(4);
current.cab_date = getDay.getDisplayValue();
} else if (t == 3) {
getDay.addDaysLocalTime(3);
current.cab_date = getDay.getDisplayValue();
} else if (t == 4) {
getDay.addDaysLocalTime(2);
current.cab_date = getDay.getDisplayValue();
} else if (t == 5) {
getDay.addDaysLocalTime(1);
current.cab_date = getDay.getDisplayValue();
} else if (t == 6) {
getDay.addDaysLocalTime(7);
current.cab_date = getDay.getDisplayValue();
} else if (t == 7) {
getDay.addDaysLocalTime(6);
current.cab_date = getDay.getDisplayValue();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 08:48 AM
Hi @bbf35621 missed a line, internally time is stored in UTC. So you need one more adjustment to store date/time in UTC.
var getDay = new GlideDateTime(current.start_date);
getDay.subtract( getDay.getLocalTime() ); // subtract the time portion of dateTime
getDay.add( 9 * 60 * 60 * 1000); // add 9 hours in milliseconds
getDay.subtract(getDay.getTZOffset()); // subtract timezone offset to get UTC time
var t = getDay.getDayOfWeekLocalTime();
Also you'll notice your addDaysLocalTime is off by '1' due to this adjustment.
hope that helped
--
Bala Guthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 11:41 AM
Hi @bbf35621 the code I posted works on my instance; please provide screenshots showing before and after states of the change at play here.
--
BalaG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 02:52 PM
I created a before Business Rule,
This is the script I followed your suggestion,
var getDay = new GlideDateTime(current.start_date);
getDay.subtract(getDay.getLocalTime()); // substract the time portion of datetime
getDay.add(9*60*60*1000); // add 9 hours in milliseconds
getDay.subtract(getDay.getTZOffset()); //substract timezone offset to get UTC time
var t = getDay.getDayOfWeekLocalTime();
if (t == 1) {
getDay.addDaysLocalTime(5);
current.cab_date = getDay.getDisplayValue();
} else if (t == 2) {
getDay.addDaysLocalTime(4);
current.cab_date = getDay.getDisplayValue();
} else if (t == 3) {
getDay.addDaysLocalTime(3);
current.cab_date = getDay.getDisplayValue();
} else if (t == 4) {
getDay.addDaysLocalTime(2);
current.cab_date = getDay.getDisplayValue();
} else if (t == 5) {
getDay.addDaysLocalTime(1);
current.cab_date = getDay.getDisplayValue();
} else if (t == 6) {
getDay.addDaysLocalTime(7);
current.cab_date = getDay.getDisplayValue();
} else if (t == 7) {
getDay.addDaysLocalTime(6);
current.cab_date = getDay.getDisplayValue();
}
This is what I fill out before submitting a Change,
Then, I submit the change. This is what it populated on CAB date/time as Friday 29th but ended up 6 PM,
When I edit a different date in the Planned start date, the CAB date changed to Friday the 22nd but with the same 6 PM,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 09:23 AM
Hi @bbf35621 another optimization; you can replace your chain of if statements with something like this
var delta = t > 5 ? 12 - t : 5 - t ;
getDay.addDaysLocalTime( delta );
current.cab_date = getDay.getDisplayValue();
hope that helps
--
Bala Guthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 06:45 PM
Hi @bbf35621 the fact that all the changes to the date/time object did not change the cab time is a bit suspicious, some context is missing. Anyway, my last guess is your timezone, are you perhaps in a timezone 9 hours ahead of UTC?
--
Bala G
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2023 08:04 AM
System time should be UTC, and the default TZ should be Eastern.