Schedule job for specific day on selected months

denu
Kilo Expert

Hi,

I have a requirement to create ticket and subtasks through a template on specific date on selected month for team to perform health checks within this year. Also this will extend for each years when we know the dates.

8 March 2022
6 April 2022
18 April 2022
6 June 2022
23 Sep 2022
25 Sep 2022
18 Dece 2022
 22 December 2022

Is there a anyway to add these dates into a one scheduled job instead of creating multiple scheduled for these dates?

3 REPLIES 3

Robbie
Kilo Patron
Kilo Patron

Hi Denu,

A rudimental approach based on the fixed requirement that the script has to run on said dates (and not a reoccurring monthly basis for example) would be to implement similar to the below. You would need to implement this as a conditional Scheduled Job and adapt accordingly for what you want to execute or trigger.

Ideally we would externalise these dates into a system property for example so you wouldn't have to update the code or Scheduled job. This however should get you started.

To help others, please mark correct and/or helpful.

Thanks,

Robbie

 

Script:

answer = false;
var todaysDate = new GlideDateTime().getDate();
//gs.log('Date: ' + todaysDate); // Log statement for your testing
var arrayUtil = new ArrayUtil();
var datesToRun = new Array("2022-02-15", "2022-02-11");
//gs.log(datesToRun.toString()); // Log statement for your testing
var result = arrayUtil.contains(datesToRun, todaysDate);
//gs.log('Result: ' + result); // Log statement for your testing
if(result){
answer = true;
}
//gs.log('Answer: ' + answer); // Log statement for your testing

 

 

Robbie
Kilo Patron
Kilo Patron

Hi Denu,

Did you see my response and have a chance to run the script?

So as to help others, can you please mark my response as correct and/or helpful.

 

Thanks,

Robbie

kimpprice
Tera Contributor

Hi all,

I just used the code above and it does work!

Thank you so much,

Kim