Timezone issue
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited an hour ago
Hi
We tested the following script and it worked fine then:
var currentDate = new GlideDateTime();
// Set the date to the first day of the next month
currentDate.addMonths(1);
currentDate.setDayOfMonth(1);
// Subtract one day to get the last day of the current month
currentDate.addDays(-1);
while (currentDate.getDayOfWeek() === 6 || currentDate.getDayOfWeek() === 7) {
currentDate.addDays(-1);
}
var lastWorkingDayOfMonth = currentDate.getLocalDate();
var lastworkingday = lastWorkingDayOfMonth.getDayOfMonthUTC();
var reportdate = new GlideDate().getDayOfMonthUTC();
var isLastBusinessDay = (lastworkingday == reportdate);
var report_date = new GlideDateTime();
var day_in_week = report_date.getDayOfWeekUTC();
// 1-Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday, 6-Saturday, 7-Sunday
var days_in_month = report_date.getDaysInMonthUTC();
var day_of_month = report_date.getDayOfMonthUTC();
var isLastDay = (day_of_month == days_in_month);
var isWeekend = (day_in_week == 6 || day_in_week == 7);
if ((isLastDay && !isWeekend) || isLastBusinessDay){
// Execute the flow logic here (the code you want to run on the last working day)
gs.log("Running flow on the last working day of the month");
// gs.print("Running flow on the last working day of the month");
runJob();
}
else {
// Optional: Reschedule the flow for the next working day
// Or, skip running the flow and log an error
gs.log("Skipping flow execution: Not the last working day.");
}
function runJob() {
try {
// Execute Synchronously: Run in foreground. Code snippet has access to outputs.
var result = sn_fd.FlowAPI.getRunner().subflow('global.time_sheets_for_current_month').inBackground().run();
//var outputs = result.getOutputs();
// Current subflow has no outputs defined.
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
}
It is supposed to trigger a subflow on the last business day of every month. IT did run correctly on the 30th of September. However, it also triggered subflow on the 1st of October.
Can someone please advise why that would have happened ?
Thank you
0 REPLIES 0