Trying to run a scheduled job at particular times

prudhvig
Tera Expert

Hi,

I am new to SNOW and finding it very difficult to script the conditions for running Scheduled Jobs.

1. Need a run a scheduled job quarterly

2. Need to run a scheduled job on 15th April every year

3. Need to run a scheduled job on 15th of every 3 months

4. Need to run a scheduled job on 1st Monday of every month

Could someone please help me in this. I have been trying to see the documentation but unable to get this.

Thanks in advance.

1 ACCEPTED SOLUTION

Gowrisankar Sat
Tera Guru

1) Run quarterly:



Run: Monthly


Day: 1



Conditional: true


condition:


function checkquarterly() {


var now = new Date();


var month = now.getMonth();


var result = false;


if(month == 3 || month == 6 || month == 9 || month == 12) {


result = true;


}


return result;


}


checkquarterly();




2) Run 15th of april:



Run: Monthly


Day: 15



Conditional: true


condition:


function checkaprilmonth() {


var now = new Date();


var month = now.getMonth();


var result = false;


if(month == 4) {


result = true;


}


return result;


}


checkaprilmonth();




3) Run 15th of every three months:



Run: Monthly


Day: 15



Conditional: true


condition:


function checkquarterly() {


var now = new Date();


var month = now.getMonth();


var result = false;


if(month == 3 || month == 6 || month == 9 || month == 12) {


result = true;


}


return result;


}


checkquarterly();



4) 1st monday of every month:



Run: on demand



Conditional: true


condition:


new Date().getDay() == 1 && new Date().getDate() <8


View solution in original post

5 REPLIES 5

Gowrisankar Sat
Tera Guru

1) Run quarterly:



Run: Monthly


Day: 1



Conditional: true


condition:


function checkquarterly() {


var now = new Date();


var month = now.getMonth();


var result = false;


if(month == 3 || month == 6 || month == 9 || month == 12) {


result = true;


}


return result;


}


checkquarterly();




2) Run 15th of april:



Run: Monthly


Day: 15



Conditional: true


condition:


function checkaprilmonth() {


var now = new Date();


var month = now.getMonth();


var result = false;


if(month == 4) {


result = true;


}


return result;


}


checkaprilmonth();




3) Run 15th of every three months:



Run: Monthly


Day: 15



Conditional: true


condition:


function checkquarterly() {


var now = new Date();


var month = now.getMonth();


var result = false;


if(month == 3 || month == 6 || month == 9 || month == 12) {


result = true;


}


return result;


}


checkquarterly();



4) 1st monday of every month:



Run: on demand



Conditional: true


condition:


new Date().getDay() == 1 && new Date().getDate() <8


Thank you very much for the help Gowrisankar.



The fourth condition is being shown as an error as below:



find_real_file.png


Could you please tell why? Thanks.


Try this:



function checkmonday() {


var now = new Date();


var day = now.getDay();


var dat = now.getDate();


var result = false;


if(day == 1 && date <8) {


result = true;


}


return result;


}


checkmonday();


Try this:



function checkmonday() {


var now = new Date();


var day = now.getDay();


var date = now.getDate();


var result = false;


if(day == 1 && date <8) {


result = true;


}


return result;


}


checkmonday();