schedule job script not executing, the script works in background script

Sharique Azim
Kilo Sage

 Hi Team,

I am facing this unusual issue where a schedule job does not trigger for a schedule job, however the same works when run from background script.

The condition is something like this

var chg = new GlideRecord('change_request'); 
chg.addEncodedQuery('active=true^end_dateRELATIVELE@dayofweek@ago@7^state=0'); 
//chg.addEncodedQuery('active=true^end_dateRELATIVELE@dayofweek@ago@7^state=0^assignment_group.nameSTARTSWITHservicenow^number=CHG0041873');
chg.query(); gs.log('chg 001');
while(chg.next()){ 
	gs.log('chg 002');
	

chg.state="4"; 
chg.close_code= 'Auto-terminated in review'; 
chg.close_notes ='Auto-term abandoned as change exceeded 7 days after the planned end date.'; 
chg.work_notes ='Auto-term abandoned as change exceeded 7 days after the planned end date.'; 
chg.update(); 
 	gs.log('chg 003' +chg.number);

} 

This although is supposed to run everyday at 23:50 , but there is no trace in the sys_trigger table. 

Also, please note when i force execute it , the logs can be seen but not the action, i.e. change does not updates/closes.

Btw, i have similar scheduled scripts running for the condition, all running in global application

var chg = new GlideRecord('change_request'); 
chg.addEncodedQuery('active=true^end_dateRELATIVELE@dayofweek@ago@7^state=-2'); 
chg.query(); 
while(chg.next()){ 
	

chg.state=4; 
chg.close_code= 'Auto-terminated in scheduled'; 
chg.close_notes ='Auto-term abandoned as change exceeded 7 days after the planned end date.'; 
chg.work_notes ='Auto-term abandoned as change exceeded 7 days after the planned end date.'; 
chg.update(); 
 
} 

Can you please point me towards something useful?

 

Regards,

Shariq

15 REPLIES 15

johnfeist
Mega Sage
Mega Sage

Hi Shariq,

I can offer two suggestions.  First, add a diagnostic to the log by adding a getRowCount() after you do the chg.query() to confirm that you are actually getting data returned.

The other is that state is an integer.  In the script that is not working, you are assigning a string while in the one that works you are assigning an integer.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hi John,

 

As you already see, the logs are are coming correctly. The state field is set to a string variable now, earlier it was set as integer, and yet it didnt work.

Hi Shariq,

Did you try check script shared in my previous comment and try to check rowCount

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Have you confirmed that your query is getting results.  You can also try using .setDisplayValue() to assign the state and see if that works.

:{)

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster