- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 04:27 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- 3,213 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 04:51 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 06:49 AM
SC_Tasks are already closed.
RITM Screenshot

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 11:18 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2022 03:13 AM
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 05:38 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 06:50 AM
Hi
SC_Tasks are already closed. Due to workflow issue RITM Stage was impacted and didn't close REQ