- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 03:40 AM
Hi Team,
Can someone help to update 500 ritm records fix script
A fix script needs to update the RITM records to:
Approval : Rejected
State Closed incomplete
Stage Closed incomplete
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2025 02:58 AM
you can enhance it further.
// give correct query, correct state, stage value to compare
var gr = new GlideRecord('sc_req_item');
gr.addQuery('state', '!=', 4); // Only update if not already closed incomplete
gr.setLimit(500); // Limit to 500 records
gr.query();
while (gr.next()) {
gr.approval = 'rejected';
gr.state = 4; // Closed Incomplete
gr.stage = 'Closed Incomplete';
gr.update();
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("sysapproval", gr.getUniqueValue());
gr.addQuery("state", "requested");
gr.query();
while (gr.next()) {
gr.state = 'rejected';
gr.comments = 'Auto rejected as RITM is closed';
gr.update();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2025 11:13 AM
Here we have one more issue.. Lots of mail triggering , Please help me?
Your current script is directly updating the approval and RITM states in ServiceNow, which is triggering notification rules and business logic — especially since you're changing the approval state and setting RITMs to closed/incomplete. That explains the mail blast i an experiencing. Could you please me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 03:51 AM - edited ‎06-18-2025 03:51 AM
HI @vivek11
Try the below script.
var rec = new GlideRecord('sc_req_item');
rec.addEncodedQuery('sys_id=b43afa88c396221091ea5242b40131a7'); // MODIFY THE QUERY AS REQUIRED
rec.query();
while(rec.next()){
rec.setValue('stage','closed_incomplete');
rec.state = '4';
rec.approval ='rejected';
rec.update();
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2025 02:45 AM
Hi @J Siva
Thank you for your quick reply.
I have one more issue — the related sysapproval_approver records for the same RITM are not being updated to "Rejected." Could you please help me with this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2025 02:55 AM
Hi @vivek11
Since it's on a different table, write a separate script to update the approval records.
Try the below script.
var rec = new GlideRecord('sysapproval_approver');
rec.addEncodedQuery('source_table=sc_req_item^sysapproval.sys_idIN9fd4ba35c318221091ea5242b4013177,b1275506eb43011008f2951ff15228d1'); //UPDATE THE SYS_ID AS REQUIRED (RITM SYS_IDs)
rec.query();
while(rec.next()){
rec.state ='cancelled';
rec.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2025 01:54 PM
Hi, you can help me?
I need to update almost 24 that was Closed Skipped in incorrect way...
I need change every single record for closed complete
You have ideal that i can make this?