- 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-18-2025 03:45 AM
so what script did you start with and where are you stuck?
something like this
// 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();
}
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-19-2025 02:44 AM
Hi @Ankur Bawiskar
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: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-20-2025 02:54 AM
Thank you @Ankur Bawiskar