How to set closure(closed_at, closed by, duration and business durtion) for Active is false RITMs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 11:20 AM
Hi ,
I have old records of RITM which having closer details were null even though active is set to false so I need to set those fields (closed_at, closed by, duration and business durtion) How can I achieve it through fix script
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 11:51 AM
Hi,
Why does it need to be a fix script? You could also create a Flow that sets these values.
It should be fairly easy, no coding required.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 11:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 12:07 PM
Sure.
Something like this might work, be sure to test the script and expected outcome, before running in production.
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addEncodedQuery('your encoded query here');
ritmGR.query();
while (ritmGR.next()){
ritmGR.setValue('field name goes here', 'data to set goes here');
// repeat above line for each field that needs to be set
ritmGR.setWorkflow(false); // prevent running other business rules and flows
ritmGR.autoSysFields(false); // prevent setting the sysfields when an update happens
ritmGR.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 12:46 PM
Hello @raj99918 ,
I hope this script functions will help you to calculate the duration.
if (current.state != 'closed_complete' && current.state != 'closed_abandoned') {
current.closed_at = null;
current.duration = null;
}
else {
var opened_at = current.opened_at.dateNumericValue();
if (current.closed_at.nil() || current.state.changes()) {
current.closed_at = new GlideDateTime();
}
var closed_at = current.closed_at.dateNumericValue();
current.duration = new GlideDuration(closed_at-opened_at);
}
calDateDiff(String, String, boolean)
Calculate the difference between two dates using the default calendar.
dateDiff(String, String, boolean)
Calculates the difference between two dates. This method expects the earlier date as the first parameter and the later date as the second parameter; otherwise, the method returns the difference as a negative value.
These functions will help you.
Please hit the helpful button.
Thank you.