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

The above script doesnt use any property, its a clean javascript code which will run in SN instance conditional box also.


Hi ...


I have one more question..



When I run this script the Date() function always returns the date and time in PDT time zone.. Though I have set it to IST time zone.. Why it is running in that time zone??


Hi,

I Used the same script to schedule every month on 3rd Tuesday and with RUN - Daily 10 AM..

For testing purpose when I click on execute now no request is created am I missing something.

 

*There is no issue with the script creating request if I uncheck the conditional checkbox and click on execute now request is created.

 

 

Thanks

slperry92
Kilo Explorer

Srikanth i have a similar issue where I'm trying to program a template schedule. I want the template to auto ticket on the 17th day after the 2nd Tuesday of each month. Can you help me with the logic that would go in the conditional area? Thank you


Dan Franko2
Kilo Contributor

I had to do something similar and I think momentJS is your friend here.   See Accessing Moment.js on Server side scripting for how to get it in your environment.



var MaintananceSchedule = Class.create();


MaintananceSchedule.prototype = {


      initialize: function() {


      },


schedule: function(weekOfMonth,dayOfWeek){


var moment = MomentJS.moment();


var day = moment().day(moment().isoWeekday()).format("dddd");


var week = moment().week() - moment().startOf('month').week() + 1;


return (day == dayOfWeek && week == weekOfMonth);


},


      type: 'MaintananceSchedule'


};



I created a script include where you pass the week of the month needed and the day that's needed to match.   So, for instance:



new MaintananceSchedule().schedule('4','Thursday')



That's all you would need in the conditional.