- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2022 11:21 PM
Hi,
I have one requirement, in that scheduled job should be trigger first Monday of every month. I have tried but in that way its not working please find the attach snapshot. could you please suggest me proper way.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 12:09 AM
Hi
Try below.? See the yellow lines in screenshot. Don't forgot to mark my answer as correct if that helps.
Condition Script:
answer = (new GlideDateTime().getDayOfMonthLocalTime() <= 7);
Screenshot:
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 02:16 AM
Hi Manish,
Following script will get the first Monday of month.
function getFirstMonday() {
var gdt = new GlideDateTime();
var curMonth = gdt.getMonthLocalTime();
var dow = gdt.getDayOfWeekLocalTime();
gdt.addDaysLocalTime(-(dow - 1));
var chkMonth = gdt.getMonthLocalTime();
if (curMonth != chkMonth) {
gdt.addDaysLocalTime(7);
} else {
var week = Math.floor(gdt.getDayOfMonthLocalTime() / 7);
gdt.addDaysLocalTime(-(week * 7));
}
return gdt.getLocalDate();
}
var today = (new GlideDateTime()).getLocalDate();
var firstMonday = getFirstMonth();
answer = (today == firstMonday);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 02:20 AM
Can be shorten like below.
function checkFirstMonth() {
var today= new GlideDateTime();
var gdt = new GlideDateTime();
var curMonth = gdt.getMonthLocalTime();
var dow = gdt.getDayOfWeekLocalTime();
gdt.addDaysLocalTime(-(dow - 1));
var chkMonth = gdt.getMonthLocalTime();
if (curMonth != chkMonth) {
gdt.addDaysLocalTime(7);
} else {
var week = Math.floor(gdt.getDayOfMonthLocalTime() / 7);
gdt.addDaysLocalTime(-(week * 7));
}
//return gdt.getLocalDate();
return (today == gdt);
}
answer = getFirstMonth();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 02:23 AM
Hi,
you can use condition field
Try to use GlideDateTime()
Also check point mentioned by Musab
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader