fix script to update RITM Record

vivek11
Tera Contributor

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

1 ACCEPTED SOLUTION

@vivek11 

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.

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

View solution in original post

12 REPLIES 12

Seems you accepted a solution earlier. that script proposed by Ankur needs a change to process all sc_req_item records and related sysapproval_approver records:

 

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';
	gs.info('update req item; ' + gr.number);
	gr.setWorkflow(false);
//    gr.update();

    var grsa = new GlideRecord("sysapproval_approver");
    grsa.addQuery("sysapproval", gr.getUniqueValue());
    grsa.addQuery("state", "requested");
    grsa.query();
    while (grsa.next()) {
        grsa.state = 'rejected';
        grsa.comments = 'Auto rejected as RITM is closed';
		grsa.info('update approval.');
		grsa.setWorkflow(false);
 //       grsa.update();
    }
}

un-comment the 'update()' lines after testing. Notifications should cease from the updates.

Thank you, in my case i need change a list of record like, ex: [RITMxxxxx,RITMxxxxx] this is a point that i have a little doubt.

I suggest you start a new thread, as a (corrected) solution is here for what it seems you originally asked for. And be explicit in what your goal is.