- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 06:07 AM
I am looking to implement a solution to Auto Close Change Requests that are older than 6months any help appreciated/
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 06:16 AM
you can use scheduled job for this
something like this in daily scheduled job but please enhance
(function executeScheduledJob() {
var sixMonthsAgo = new GlideDateTime();
sixMonthsAgo.addMonthsUTC(-6);
var grChangeRequest = new GlideRecord('change_request');
grChangeRequest.addQuery('sys_created_on', '<', sixMonthsAgo);
grChangeRequest.addActiveQuery();
grChangeRequest.query();
while (grChangeRequest.next()) {
grChangeRequest.state = '3';
grChangeRequest.active = 'false';
grChangeRequest.close_code = 'Closed by Automation';
grChangeRequest.close_notes = 'Automatically closed as it is older than six months.';
grChangeRequest.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
‎04-01-2025 06:22 AM
Hello @Ralton Stewart ,
You can achieve this requirement using Flow Designer without writing any script by leveraging a scheduled-based flow.
Steps to Implement:
Lookup Records: Retrieve all Change Requests where the state is not closed and the creation date is older than 6 months.
For Each Loop: Iterate through the retrieved records and update their state to Closed. You can also set the Close Notes and Close Code, if required.
This approach ensures that old Change Requests are automatically closed without manual intervention.
I hope this helps resolve your query.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2025 06:16 AM
you can use scheduled job for this
something like this in daily scheduled job but please enhance
(function executeScheduledJob() {
var sixMonthsAgo = new GlideDateTime();
sixMonthsAgo.addMonthsUTC(-6);
var grChangeRequest = new GlideRecord('change_request');
grChangeRequest.addQuery('sys_created_on', '<', sixMonthsAgo);
grChangeRequest.addActiveQuery();
grChangeRequest.query();
while (grChangeRequest.next()) {
grChangeRequest.state = '3';
grChangeRequest.active = 'false';
grChangeRequest.close_code = 'Closed by Automation';
grChangeRequest.close_notes = 'Automatically closed as it is older than six months.';
grChangeRequest.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
‎04-01-2025 06:22 AM
Hello @Ralton Stewart ,
You can achieve this requirement using Flow Designer without writing any script by leveraging a scheduled-based flow.
Steps to Implement:
Lookup Records: Retrieve all Change Requests where the state is not closed and the creation date is older than 6 months.
For Each Loop: Iterate through the retrieved records and update their state to Closed. You can also set the Close Notes and Close Code, if required.
This approach ensures that old Change Requests are automatically closed without manual intervention.
I hope this helps resolve your query.
Thank you!