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

Sharique Azim
Mega 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

Ian Mildon
Tera Guru

For something like this I would suggest creating a scheduled Flow within Flow Designer instead of your current script.

find_real_file.png

 

We have still not accommodated flow designer in our  development yet. so maybe not now.

Dubz
Mega Sage

The change process is workflow driven, why not just add a timer into the workflow and cancel it from there if the time elapses? 

Good approach, however, Ill have to change the workflow and will update you.

Hello Shariq, 

Did you get a chance to resolve this issue, because I'm also facing the same issue.

This is the code given below, I'm able to update the records from background script but when I tried it with scheduled job, it is not working. Can you please help me on this

var core = new GlideRecord('core_company');
core.addEncodedQuery('u_taq_valid_days_remaining!=NULL');
core.query();
core.getRowCount();
while(core.next()) {
var date = core.u_taq_valid_days_remaining.getValue();
    year = date - 1;
   core.setValue('u_taq_valid_days_remaining', year);
   core.update();
}

Thanks and regards.