The CreatorCon Call for Content is officially open! Get started here.

Script not working in scheduled reports

Sireesha7
Tera Contributor

Hi Team,

 

Good Day !

 

I wrote a script in Scheduled report and it's not working and when I run same script in background script it's working fine.

 

The scenario is a scheduled report that is supposed to run on the second Monday of each quarter . However, it is incorrectly triggering on the first Monday of every week. 

 

I am attaching the script and background script executions as well.

Please check and do the needful !

 

image (9).pngimage (10).png

 

 

Thanks & Regards,

Sai Sireesha G

 

20 REPLIES 20

@Chaitanya ILCR 

 

Tried, but no luck 😞

 

Please try 

getMonthLocalTime()

di_zhang3_0-1749111254044.png

 

Hi,

Some pointers.

You wanted the report to run on the second Monday of every quarter.

But you've scheduled it to run on a monthly basis (on the first day of each month).

So, in my head, when the report runs, and it's not the correct date, you will not run it again later that month, because next run execution would be the following month.

 

Therefore I suggest you change the execution to run weekly on Mondays instead.
In the script, check if it is the right month, and the right week. That should be it.

 

And also, I would wrap the entire script in a function, and set the answer variable as a result of the function call.

 

Example below.

answer = checkDate();

// Only run on the first month of each quarter, and only on the second monday of that month
function checkDate(){
	var gdt = new GlideDateTime();
	var month = gdt.getMonth();
	var dayMonth = gdt.getDayOfMonth();
	if ((month == 1 || month == 4 || month == 7 || month == 10) && dayMonth > 7 && dayMonth <= 14){
		return true;
	}
	else{
		return false;
	}
}

 

Sireesha7
Tera Contributor

@OlaN 

 

As per your inputs, I have tried but no luck 😞

 

Chaitanya ILCR
Mega Patron

Hi @Sireesha7 ,

you script looks good 

ChaitanyaILCR_0-1749105483368.png

just change the Run to Daily or Weekly from Monthly

ChaitanyaILCR_0-1749105653049.png

if configured weekly like above you can use script (weekly on mondays)

var gdt = new GlideDate();
var day = gdt.getDayOfMonthNoTZ()
var month = gdt.getMonthNoTZ()

answer = (day > 7 && day < 14) && (month == 1 || month == 4 || month == 7 || month == 10);

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya