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
make your job run daily and it will handle this
(function() {
var gdt = new GlideDateTime();
var gDate = new GlideDate();
gDate.setValue(gdt.getDate());
var dayOfMonth = gDate.getDayOfMonth();
var dayOfWeek = gdt.getDayOfWeek(); // 1=Monday ... 7=Sunday
// Run only on weekdays (Monday=1 to Friday=5)
var isWeekday = (dayOfWeek >= 1 && dayOfWeek <= 5);
// If today is 8th and weekday, run
if (dayOfMonth === 8 && isWeekday) {
gs.info('Running on 8th which is a weekday');
// Call your RITM auto-creation logic here
return;
}
// If today is Monday, check if 8th was on weekend (Sat or Sun)
if (dayOfWeek === 1) { // Monday
var gdtYesterday = new GlideDateTime();
gdtYesterday.addDaysLocalTime(-1);
var dayOfMonthYesterday = gdtYesterday.getDayOfMonth();
// If yesterday was 8th and weekend, run today (Monday)
if ((dayOfMonthYesterday === 8) && (gdtYesterday.getDayOfWeek() >= 6)) {
gs.info('8th was weekend, running on Monday');
// Call your RITM auto-creation logic here
return;
}
}
gs.info('Not the scheduled day for running RITM creation');
})();
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
i customized this with my day like 7 but it did not worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what debugging did you do?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
instead of 8 day i edited it with 7 and run it as background script , then in schedule job , but schedule job did not run and no records were created
