Regarding glideDateTime
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have a piece of code and in that script I want RITMs to autocreate on every 8th dau of month, I want it to run on 8th day of every month and if 8th day is a weekend it should skip and then run on Monday i.e. should only run on weekdays.But when I am executing it is not running as desired.
Can anyone help me with a workaround?
date script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ShubhangiA77524 ,
Please review below code -
// Get current date/time
var now = new GlideDateTime();
var gDate = new GlideDate();
gDate.setValue(now.getDate());
// Get day of month and day of week (1=Sunday, 7=Saturday)
var dayOfMonth = parseInt(gDate.getDayOfMonth(), 10);
var dayOfWeek = parseInt(gDate.getDayOfWeek(), 10);
gs.info("Today: " + gDate.getDisplayValue() + ", Day of month: " + dayOfMonth + ", Day of week: " + dayOfWeek);
// Run logic only on 8th or next Monday if 8th was weekend
var shouldRun = false;
// Case 1: today is 8th and weekday
if (dayOfMonth === 8 && dayOfWeek >= 2 && dayOfWeek <= 6) {
shouldRun = true;
}
// Case 2: today is 9th (Monday) and the 8th was Sunday
else if (dayOfMonth === 9 && dayOfWeek === 2) { // Monday = 2
var prevDate = new GlideDate();
prevDate.setValue(gDate);
prevDate.addDaysUTC(-1);
var prevDayOfWeek = parseInt(prevDate.getDayOfWeek(), 10);
if (prevDayOfWeek === 1) shouldRun = true; // 8th was Sunday
}
// Case 3: today is 10th (Monday) and the 8th was Saturday
else if (dayOfMonth === 10 && dayOfWeek === 2) {
var prev2 = new GlideDate();
prev2.setValue(gDate);
prev2.addDaysUTC(-2);
var prev2DayOfWeek = parseInt(prev2.getDayOfWeek(), 10);
if (prev2DayOfWeek === 7) shouldRun = true; // 8th was Saturday
}
if (shouldRun) {
gs.info(" Running RITM creation logic today.");
// ==== Your RITM creation logic here ====
} else {
gs.info("⏸ Not the correct day to run the job.");
}
If you found my response helpful, please mark it as helpful and accept it as the solution.
Thank you
Nawal Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I runned it in background script and it showed following log:
*** Script: Today: 11/07/2025, Day of month: 6, Day of week: 5
*** Script: ⏸ Not the correct day to run the job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ShubhangiA77524 ,
add the date that you want to create a RITM and test it.
so it will confirm that it will work.
If you found my response helpful, please mark it as helpful and accept it as the solution.
Thank you
Nawal Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I used the day 7 in this script as today is 7 but it did not worked, can you help me with it
