Send Notification Every Month Second Monday

Mark Wood
Tera Contributor

Hello Team,

 I need to send a notification every month on the second Monday. If the Monday happens to be a holiday, the notification should be sent on the next working day.

Could you please guide me on how to achieve this using Flow Designer?

Thank you.

4 REPLIES 4

Abhijit4
Mega Sage

Hi @Mark Wood 

 

This can easily be done with scheduled job with below script:

Trigger Type: 

Abhijit4_0-1746959615914.png

Script:

  var now = new GlideDateTime();
    var dayOfMonth = now.getDayOfMonthLocalTime();
    var dayOfWeek = now.getDayOfWeekLocalTime(); // 1=Monday, 2=Tuesday, ..., 7=Sunday

    // Check if it's the second Monday of the month
    if (dayOfWeek == 1 && dayOfMonth >= 8 && dayOfMonth <= 14) {
			var sched = new GlideSchedule("your_holiday_schedule_sys_id");
			//This loop will automatically be skipped if its not holiday
            while (sched .isInSchedule(now)) {
                now.addDaysLocalTime(1); //this will keep on adding days until it is holiday
            }
            gs.eventQueueScheduled("event_name", current, "param1", "param2", now);
        }
    }

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hello @Abhijit4,

There seems to be a mistake in your code. You need to initialize the object for the GlideScheduled API and use that object to check whether the record is within the schedule or outside it. Currently, you're checking it using the GlideRecord object, which I believe won’t work as intended. I’ve attached the updated code below.

Thank you

var now = new GlideDateTime();
var dayOfMonth = now.getDayOfMonthLocalTime();
var dayOfWeek = now.getDayOfWeekLocalTime(); 


if (dayOfWeek == 1 && dayOfMonth >= 8 && dayOfMonth <= 14) {
    var grSchedule = new GlideRecord('cmn_schedule');
    grSchedule.addQuery('name', 'your_holiday_schedule_name'); 
    grSchedule.query();

    if (grSchedule.next()) {
        var schedule = new GlideSchedule(grSchedule.sys_id);
       

        // Keep moving forward until we find the next valid (working) day
        while (schedule.isInSchedule(now)) {
            now.addDaysLocalTime(1);
        }

        gs.eventQueueScheduled("event_name", current, "param1", "param2", now);
    }
}

@Abhijeet_Pawar  You are absolutely right, I missed to use GlideSchedule. Now I have updated my code to reflect GlideSchedule. Also, we may not need to glide into cmn_schedule table. We can store schedule sys_id in system property and use it directly.

 

Also, your while condition should be other way around

 

while (schedule.isInSchedule(now)) { // not(!) should not be used here as schedule holds holiday dates so we should loop until date is not in schedule ( which means not a holiday )
            now.addDaysLocalTime(1);
        }

 

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Ankur Bawiskar
Tera Patron
Tera Patron

@Mark Wood 

difficult to achieve this using flow designer, you can use the approach shared by @Abhijit4 and let us know the feedback

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader