Update Stage on RITM using script

Community Alums
Not applicable

Hi Team,

We had an issue with workflow so requests were not closed properly & we have fixed that issue. But want to close the old records.

RITM state is set to Closed Complete on them but Stage is still showing as Fulfillment and REQ is also active.

How can we set Stage (field type - workflow) field to Completed and close out REQ using script?

Thank you.

1 ACCEPTED SOLUTION

Martin Ivanov
Giga Sage
Giga Sage

var grReqItems = new GlideRecord('sc_req_item');

grReqItems.addQuery('stage', '!=', 'complete');

grReqItems.query();

while(grReqItems.next()){

grReqItems.setValue('stage', 'complete');

grReqItems.update()

}

 

Please note that this will close all RITMS that are not closed. If want to close only specific items, please provide the query and I will provide you with the script.

Mark Correct and Helpful if appropriate. Thanks


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

View solution in original post

9 REPLIES 9

Martin Ivanov
Giga Sage
Giga Sage

var grReqItems = new GlideRecord('sc_req_item');

grReqItems.addQuery('stage', '!=', 'complete');

grReqItems.query();

while(grReqItems.next()){

grReqItems.setValue('stage', 'complete');

grReqItems.update()

}

 

Please note that this will close all RITMS that are not closed. If want to close only specific items, please provide the query and I will provide you with the script.

Mark Correct and Helpful if appropriate. Thanks


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

Community Alums
Not applicable

Hi Martin,

Thanks for the update.

It works but list view still shows Fulfillment!

find_real_file.png

Thank you.

I have my own name for this Stage column, "List view Stage". my way of controlling this is as below:

- go to your workflow

- open any activity

- under the name, there should be a Stage input box. this controls what you see on your lists.

- select a proper stage for all or some of your activities you have in workflow. repeating a same stage does not produce duplicate views.

 

I hope that helps.

Martin Ivanov
Giga Sage
Giga Sage

If you have SC_Task records, related to the ritms, you have to complete these as well. Is this screenshot from REQ or RITM?


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024