We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

@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

Sumanth16
Mega Patron

Hi @SAM321 ,

 

Select daily in scheduled job and condition would become true only on 2nd tuesday  of every month using below script

 

 

function checksecondstuesday() {

 

var gdt = new GlideDateTime();

 

var day = gdt.getDayOfWeek();



var result = true;

 

  if (day == 2 && (gdt.getDate() >7 && gdt.getDate()<=14)){

 

  result = true;

 

  }

 

  return result;

 

}

 

 

Plz mark my solution as Accept, If you find it helpful.

 

 

Thanks & Regards,

Sumanth meda

 

checksecondstuesday();