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

Community Alums
Not applicable

SC_Tasks are already closed.

RITM Screenshot

Then I would suggest to go and close all the requests with another background script:

var requestGR = new GlideRecord('sc_request');
requestGR.addActiveQuery();
requestGR.query();
while(requestGR.next()){
requestGR.setValue('request_state','closed_complete')
requestGR.setValue('stage','closed_complete')
requestGR.setValue('state','3')
requestGR.update();
}

Please 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

@mjs9  if this helped you resolve the query, please mark Correct.


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

Sourabh26
Giga Guru

Hi,

 

You need to close all the task first which are associated with that RITM and then close the RITM then REQ. 

 

Mark this as Helpful/Correct if applicable.

 

Regards,

Sourabh

Community Alums
Not applicable

Hi

SC_Tasks are already closed. Due to workflow issue RITM Stage was impacted and didn't close REQ