Invalid Function definition Error in logs

Tapish Sharma1
Kilo Sage

Hi All, 

I am using below script in scheduled reports to check the month, but the script is not working 

It shows invalid function def in logs

function checkMonths(){

var a = false;
var triggerMonths = [1,3,5,7,9,11];
var currentDate = new Date();
var currentMonth = currentDate.getMonth();


for (i in triggerMonths){
if ( currentMonth == triggerMonths[i])
a=true;
}
return a;
}


checkMonths();

 

TapishSharma1_0-1668082117580.png

 

9 REPLIES 9

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Tapish Sharma1 

 

Can you try below code:

 

 

checkMonths();

function checkMonths() {
var triggerMonths = [1,3,5,7,9,11];
var currentDate = new Date();
var currentMonth = currentDate.getMonth();

for (i in triggerMonths){
if ( currentMonth == triggerMonths[i])
return true;
}
return false;
}

 

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Hi Anubhav, thanks for your reply

This script is similar right ? it gives the same result

Hi @Tapish Sharma1 

 

Yes but I guess you need to call function first and than declare function. Have you tried it? Is it giving same error log?

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Yes, it gives the same result