Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

HI All

basha shaik
Tera Contributor

Hi All,

 

I Have one question Related to scheduled job.

 

i wan trigger scheduled job every year jan month first moday.

 

I Have write condition

 

function checkmonday() {
    var gdt = new GlideDateTime();
    var day = gdt.getDayOfWeek();
    var month = parseInt(gdt.getMonth());
    
    var week = gdt.getDayOfMonth();
   
    var result = false;
    if (getDayOfWeek == 2 && getDayOfMonth <= 7 && month == 0) {   //2 is monday 0 is jan month
        gs.info('Today is the first Tuesday of the month.');
    } else {
        gs.info('Today is the not first Tuesday of the month.');
    }
    result = true;
}

checkmonday();
 
 
 
but it is trigger every month but we need yearly once that first monday of the year
 
can any one suggest 
 
 
Thanks 

 

1 REPLY 1

palanikumar
Giga Sage
Giga Sage

Hi,

I see some issue with the script. Use the below script

Note: I feel Monday represents 1, but you are using 2 in the script. Hope you tested

function checkmonday() {
    var gdt = new GlideDateTime();
    var day_week = gdt.getDayOfWeek();
    var day_month = gdt.getDayOfMonth();
    var month = parseInt(gdt.getMonth());
    var week = gdt.getDayOfMonth();
   
    var result = false;
    if (day_week == 2 && day_month <= 7 && month == 0) {   //2 is monday 0 is jan month
        gs.info('Today is the first Tuesday of the month.');
        result = true;
    } else {
        gs.info('Today is the not first Tuesday of the month.');
    }
}

checkmonday();

 

Thank you,
Palani