How to set the Duration,Business duration, Closed and Closed by fields on RITM for historical data ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 11:55 AM
Hi
How to set the Duration,Business duration, Closed and Closed by fields on RITM for historical data (Old Records)?
Help me with the Fix script
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 04:15 PM
Hi @raj99918
You can try the below Script:
var grRitm = new GlideRecord('sc_req_item');
grRitm.addActiveQuery('sys_created_onRELATIVELT@month@ahead@1');
grRitm.addActiveQuery('stateIN1,2');
grRitm.setLimit(10); // Limit the processing to 10 records for testing
grRitm.query();
// Loop through each matching RITM record
while (grRitm.next()) {
// Log the RITM being processed
gs.print('Processing RITM: ' + grRitm.sys_id);
var createdOn = new GlideDateTime(grRitm.sys_created_on);
var updatedOn = new GlideDateTime(grRitm.sys_updated_on);
var closedat=new GlideDateTime(grRitm.closed_at);
var openedat=new GlideDateTime(grRitm.opened_at);
var duration = (updatedOn.getNumericValue() - createdOn.getNumericValue()) / 86400000;
var businessDuration = (closedat.getNumericValue() - openedat.getNumericValue()) / 86400000;
gs.print(duration);
gs.print('business duration'+businessDuration);
grRitm.business_duration = businessDuration;
grRitm.closed = closedat;
grRitm.closed_by = gs.getUserID();
grRitm.update();
}
Regards,
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 06:00 AM
for historical records you need to search in Audit table and know when the ticket got closed.
Audit table is huge and querying it for each closed INC will lead to performance issue.
I would suggest to discuss this requirement with your business team
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
01-20-2025 01:06 AM
Hope you are doing good.
Did my reply answer your question?
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