The CreatorCon Call for Content is officially open! Get started here.

How to get first Monday of every month for scheduling the report.

Chaitanya Redd1
Tera Guru

Hi,

 

How to get first Monday/ Tuesday/Wednesday/Thursday of every month for scheduling the report.

I need to scheduled the report first Monday of every month.

I have tried below script it's working but there is error here that take a example : I have scheduled one report it has to be generate on second Tuesday midnight every month but it's generated first Tuesday of the month. Ex: April 7th 2020 is First Tuesday of the month and I need the report should generate on second Tuesday of the month means 14th April 2020. Please help me on this if there is any thing need to change.

function checkSecondTuesday() {
    var prefixes = ['First', 'Second', 'Third', 'Fourth', 'Fifth'];
    var result;
    var gdt = new GlideDateTime();
    var month = gdt.getMonthLocalTime();
    var day = gdt.getDayOfWeek();
    var week = gdt.getDayOfMonthLocalTime();
    var checkWeek = prefixes[0 | week / 7];
    if (checkWeek == 'Second' && day == 2) {
        result = true;
    } else {
        result = false;
    }
    return result;
}
checkSecondTuesday();

 

1 ACCEPTED SOLUTION

Megha Padale
Giga Guru

Hi Jry,

Try below code to get first monday of every month:

function checkmonday() {

var gdt = new GlideDateTime();

var day = gdt.getDayOfWeek();

var result = false;

 if (day == 1 && gdt.getDayOfMonth()<=7){

  result = true;

  }

 return result;

}

checkmonday();

 

Refer this link below, it might help you to solve it out:

https://community.servicenow.com/community?id=community_question&sys_id=033f4be1dbdcdbc01dcaf3231f96...

If my answer helped you in any way, mark answer as helpful and correct.

Thanks and regards,

Megha.

View solution in original post

5 REPLIES 5

Priyanka Chandr
Mega Guru

Hi,

The isFirstDayOfWeek method simply tells you if it is a Monday or not.

Check below link

https://community.servicenow.com/community?id=community_question&sys_id=033f4be1dbdcdbc01dcaf3231f96...

Kindly mark it correct and helpful if it solves your issue.

Thanks,

Priyanka

Megha Padale
Giga Guru

Hi Jry,

Try below code to get first monday of every month:

function checkmonday() {

var gdt = new GlideDateTime();

var day = gdt.getDayOfWeek();

var result = false;

 if (day == 1 && gdt.getDayOfMonth()<=7){

  result = true;

  }

 return result;

}

checkmonday();

 

Refer this link below, it might help you to solve it out:

https://community.servicenow.com/community?id=community_question&sys_id=033f4be1dbdcdbc01dcaf3231f96...

If my answer helped you in any way, mark answer as helpful and correct.

Thanks and regards,

Megha.

Community Alums
Not applicable

Hi Megha,

I was trying the mentioned code to get the first Monday of every month, but it is not working for the scheduled ticket. Can you please help me with how to get the first Monday of every month for the planned maintenance (auto ticket)?

Thanks & Regards,

Abyson

Community Alums
Not applicable

Hi Megha,

 

I was trying the mentioned code to get the first Monday of every month, but it is not working for the scheduled ticket. Can you please help me with how to get the first Monday of every month for the planned maintenance (auto ticket)?

 

Thanks & Regards,

Abyson