- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2023 01:55 AM
Hi,
I'm looking for a hand writing a script to bulk update the 'closed' field in a number of RITMs. The date added should match the date of the last update in the request (This is the bit I'm stuck on). They are all in a closed state but the closed date was not populated. Any help would be appreciated.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2023 02:28 AM
Hi,
Please try the below code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2023 02:28 AM
Hi,
Please try the below code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2023 02:32 AM
(function() {
// Define the target table (Requested Item)
var ritmTableName = 'sc_req_item'; // Replace with the actual table name
// Get a GlideRecord for the Requested Item table
var ritmGR = new GlideRecord(ritmTableName);
ritmGR.addQuery('active', false); // Select closed records
ritmGR.query();
// Loop through closed Requested Items
while (ritmGR.next()) {
// Get the associated request
var request = ritmGR.request;
if (request && request.get('sys_updated_on')) {
// Get the last update date of the associated request
var lastUpdate = request.get('sys_updated_on');
// Set the 'closed' field in the RITM to match the last update date
ritmGR.closed = lastUpdate;
ritmGR.update();
}
}
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-16-2023 02:46 AM
Hi,
This sounds like something you could solve with a Flow also, no coding required.
Depending on the requirements, and the volume of records to update, this could be an option for you.
Have a look at the example I've provided below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2024 08:58 AM
how can we update the close at time of ritm with last sctask closed at time in servicenow. COuld youplease help me with solution here using background script