How to schedule incident every Third Tuesday of each month??? I tried doing it by "Scheduler" and Trigger Type - "Week in month" but it's next action always gives a Monday date .

Sjoshi2
Mega Contributor

Do I have to check "glide.schedules.repeat_nth" property and set it to Day??

I also wrote this script:

var now = New DateTime();

var day = now.getDay();

gs.log("Day is :" + " " +day);

if( day == 3)

{

var rec1 = new GlideRecord("incident");

rec1.initialize();

rec1.applyTemplate("Test");

rec1.insert();

}

1 ACCEPTED SOLUTION

ghsrikanth
Tera Guru

Hi Shreya,



Please find the script to be written in conditional, this should work -



function checkThirdTuesday(workDay){


      var ordinals = ["", "1", "2", "3", "4", "5"];


      var date = String(new Date());


      var tokens = date.split(" ");




      var floatNumber = ordinals[Math.ceil(tokens[2]/7)];


      var weekDay = tokens[0];


     


      if(floatNumber == "3" && weekDay == workDay)


                    result = true;


      else


                    result = false;


      return result;


}



checkThirdTuesday('Tue');




Hopefully it helps


View solution in original post

18 REPLIES 18

Gurpreet07
Mega Sage

Create a schedule job of run type daily. Make it conditional and in condition use following script



answer = getThirdTuesday();




function getThirdTuesday(){


var dt = new GlideDateTime();


var day = dt.getDayOfWeek();


var dayOfMonth = dt.getDayOfMonth();




if(dayOfMonth < 15 || dayOfMonth > 22){       // 3rd Tuesday will always be between 14 and 23 of month and 2nd or 4th Tuesday cannot lie between these dates


    return false ;


}


if(day == 2){   // 2 for Tuesday


    return true ;


}  


return false;


}


}


ghsrikanth
Tera Guru

Hi Shreya,



Please find the script to be written in conditional, this should work -



function checkThirdTuesday(workDay){


      var ordinals = ["", "1", "2", "3", "4", "5"];


      var date = String(new Date());


      var tokens = date.split(" ");




      var floatNumber = ordinals[Math.ceil(tokens[2]/7)];


      var weekDay = tokens[0];


     


      if(floatNumber == "3" && weekDay == workDay)


                    result = true;


      else


                    result = false;


      return result;


}



checkThirdTuesday('Tue');




Hopefully it helps


Thank you sooooo much .. It actually worked.. Thanks alot


Its good to know that it has worked, could you please mark the answer as correct, so that it will be helpful for future community users