Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Cancel changes daily if Planned start date is in the past scheduled job

soraya_vally
Mega Guru

Hello Community

 

I have a requirement to create a daily scheduled job to cancel changed automatically if planned start date is in the past if the state is in Assess/Authorize state.

 

I have a start to something but need more help please. 

 

var gr= new GlideRecord("change_request");


gr.addEncodedQuery('active=true^assigned_toISEMPTY^end_dateRELATIVELE@dayofweek@ago@10');


gr.query();


while(gr.next()){


gr.state=4;


gr.update();


}
2 REPLIES 2

Harish Bainsla
Kilo Patron

hi please look below code and also check state value

var gr = new GlideRecord("change_request");

gr.addQuery('state', 'IN', 'Assess,Authorize');
gr.addQuery('active', true);
gr.addQuery('start_date', '<', gs.nowDateTime());

gr.query();

while (gr.next()) {

gr.state = 3;

gr.update();
}

Thank you Harish, 

 

I have tried the script in the scheduled job execution but doesn't seem to work yet. I also need to add a work note: The work notes are updated "The system has cancelled this Change as its in the approval phase but the Planned start date is in the past"

 

soraya_vally_0-1705394014327.png