Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to run the schedule job for every 2 weeks on saturday

Sethu Varma
Tera Expert

Hi Team,

 

I want to run the schedule job for every 2 weeks on saturday. There is no option like every 2 weeks. 

1 ACCEPTED SOLUTION

OlaN
Tera Sage
Tera Sage

Hi,

G Ponsekar answered correctly that you can have it run every other week with the "Conditional" checkbox checked.

But the script is unnecessarily complicated.

A simple "is it an odd or even week" check will do.

 

Example below.

var gdt = new GlideDateTime();
var weekNumber = gdt.getWeekOfYearUTC();
var oddOrEvenWeek = weekNumber % 2;

if (oddOrEvenWeek == 0){
	// run on even weeks, 2, 4, 6 and so on
	return true;
}

// if you want this to run on odd weeks (1,3,5,7 and so on), change the condition to --> (oddOrEvenWeek == 1)

View solution in original post

5 REPLIES 5

OlaN
Tera Sage
Tera Sage

Hi,

G Ponsekar answered correctly that you can have it run every other week with the "Conditional" checkbox checked.

But the script is unnecessarily complicated.

A simple "is it an odd or even week" check will do.

 

Example below.

var gdt = new GlideDateTime();
var weekNumber = gdt.getWeekOfYearUTC();
var oddOrEvenWeek = weekNumber % 2;

if (oddOrEvenWeek == 0){
	// run on even weeks, 2, 4, 6 and so on
	return true;
}

// if you want this to run on odd weeks (1,3,5,7 and so on), change the condition to --> (oddOrEvenWeek == 1)