How to set repeat interval for scheduled job based on condition?

poojashah27
Giga Guru

i would like to run send out email on last saturday of the month, how can i achieve that using scheduled job?

thanks

1 ACCEPTED SOLUTION

Hi Pooja,



Step 1, create an event. Event Registry - ServiceNow Wiki


Step 2: Create your scheduled job script. The scheduled job will only trigger an event if it meets the criteria I specified above "it is saturday, and it is the last saturday." Use gs.eventQueue() to trigger the event. GlideSystem - ServiceNow Wiki


Step 3: Create a notification that reacts to the event. Events and Email Notification - ServiceNow Wiki


View solution in original post

13 REPLIES 13

Chuck Tomasi
Tera Patron

Here's how I would approach it..



Run the script every day.


Use the GlideDateTime methods to find out if the day of week is Saturday (6).


Find out if adding 7 days gives you a result with a new month value, if so, you're on the last Saturday.



GlideDateTime - ServiceNow Wiki


I should have mentioned, if it is the last Saturday, trigger an event that launches the email notification.



Email Notifications - ServiceNow Wiki


Events and Email Notification - ServiceNow Wiki  


Thanks Tom. So as per my understanding i should do following:



1. create schedule item


        job ID: RunScriptJob


        trigger type: Daily


2. create email notification


        what should i choose an option here?


Hi Pooja,



Step 1, create an event. Event Registry - ServiceNow Wiki


Step 2: Create your scheduled job script. The scheduled job will only trigger an event if it meets the criteria I specified above "it is saturday, and it is the last saturday." Use gs.eventQueue() to trigger the event. GlideSystem - ServiceNow Wiki


Step 3: Create a notification that reacts to the event. Events and Email Notification - ServiceNow Wiki