Schedule report on first monday of every month

SKR
Giga Contributor

Hi,

 

I am trying to schedule a report that needs to be sent on first Monday of every month and I have used a below query, Can someone hep me understand whats wrong in the query.

function checkmonday() {
var gdt = new GlideDateTime();
var day = gdt.getDayOfWeek();
var result = false;
if (day == 1 && gdt.getDayOfMonth()<=7){
result = true;
}
return result;
}
checkmonday();

 

and I have schedule as follow:

 

RUN: Weekly

Day: Monday

Time : 8:00 AM

 

 

9 REPLIES 9

I went thought ever single example of a scheduled report and job that I could find in the system. the only thing I could see is that you have the function coded and then are calling it. Not sure if that will cause the issue but trying doing it like this.

checkmonday();

function checkmonday() {
var gdt = new GlideDateTime();
var day = gdt.getDayOfWeek();
var result = false;
if (day == 1 && gdt.getDayOfMonth()<=7){
result = true;
}
return result;
}

Also I know in the past if have had issues with doing gdt.getDayOfMonth() in an if statement in the past. You may to to put that in a variable like you did for getDayOfWeek.

Hi Brian,

I used the code which you have provided, but now the report is sent every week on monday, but I want to schedule it  for first Monday of ever month

You may want to put in case with NOW Support. I tried this in my PDI with your code. I also tried doing what @Ankur Bawiskar suggested. I even what as far as writing the script without a function call. I had log statement all over the place in the script and it was like it was completely being ignored as no logs were ever written.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you should set answer variable with true or false

I hope you are using condition field to add that script

function checkmonday() {
    var gdt = new GlideDateTime();
    var day = gdt.getDayOfWeek();
    var result = false;
    if (day == 1 && gdt.getDayOfMonth()<=7){
        result = true;
    }
    return result;
}
answer = checkmonday();

Regards
Ankur

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

@SKR 

check this link for Orlando version the GlideDateTime doesn't work fine in scheduled report condition field; they have mentioned workaround as well using Date() class of javascript

KB0827366

Regards
Ankur

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