Trigger scheduled job every month second 'week' 'monday'.

SAM321
Tera Contributor

Hi all, how to run a scheduled job every 'month' second 'week' 'monday'.
can someone suggest the conditional script for this. Thanks in advance.

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@SAM321 

  • Navigate to the Scheduled Jobs Module:

    • Go to System Definition > Scheduled Jobs.
  • Create a New Scheduled Job:

    • Click on the New button to create a new scheduled job.
  • Configure the Job:

    • Name: Give your job a meaningful name.
    • Run: Select Weekly from the dropdown. Set Monday in day
    • Time: Set the specific time you want the job to run.
    • Day of Month: Since you want the job to run on the Monday of the second week of the month, you'll need to use a script to handle this.

Here is the 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) {
        // Your job logic here
    }

 

 

Hope this helps.

 

View solution in original post

5 REPLIES 5

Priyanka_786
Tera Guru
Tera Guru

Sandeep Rajput
Tera Patron
Tera Patron

@SAM321 

  • Navigate to the Scheduled Jobs Module:

    • Go to System Definition > Scheduled Jobs.
  • Create a New Scheduled Job:

    • Click on the New button to create a new scheduled job.
  • Configure the Job:

    • Name: Give your job a meaningful name.
    • Run: Select Weekly from the dropdown. Set Monday in day
    • Time: Set the specific time you want the job to run.
    • Day of Month: Since you want the job to run on the Monday of the second week of the month, you'll need to use a script to handle this.

Here is the 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) {
        // Your job logic here
    }

 

 

Hope this helps.

 

Hi @Sandeep Rajput please look at the screenshot attached, will it works?

Screenshot (25).png

@SAM321 Change the Run from Monthly to Weekly and select the Day as Monday. Rest looks fine.