
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 06:42 AM
Hi all,
I'm trying to generate the duration of a SC Task or RITM. I found the following KB article:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0684036
I've updated the Close Ticket business rule as it suggests but the the Business Duration field is not populating...
Any help greatly appreciated. I would like to do the same for RITMs too.
Many thanks
Tracey
Solved! Go to Solution.
- Labels:
-
Request Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 07:01 AM
Hi Tracey,
Could you try this script instead?
current.active = false;
current.work_end = nowDateTime();
current.business_duration = gs.dateDiff(current.opened_at.getDisplayValue(),current.work_end.getDisplayValue(),false);
Let me know the outcome.
Please mark my answer as Correct/Helpful based on impact
Regards,
Dan H

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 09:42 AM
Give this version of the script a try:
current.active = false;
if (current.closed_by.nil())
current.closed_by = gs.getUserID();
if (current.closed_at.nil()) {
current.closed_at = gs.nowDateTime();
current.business_duration = gs.dateDiff(current.opened_at.getDisplayValue(),current.work_end.getDisplayValue(),false);
current.calendar_stc = gs.dateDiff(current.opened_at.getDisplayValue(),current.work_end.getDisplayValue(),true);
}
The former worked on RITMS on my PDI, but it's also worth trying this version. If it doesn't work again, i'll look into it further

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 10:07 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 10:35 AM
Would you update the script to:
current.active = false;
if (current.closed_by.nil())
current.closed_by = gs.getUserID();
if (current.closed_at.nil()) {
current.closed_at = gs.nowDateTime();
gs.log('[ritmDuration] opened_at: ' + current.opened_at + ' - closed.at: ' + current.closed_at);
gs.log('[ritmDuration] date diff: ' + gs.dateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),false));
current.business_duration = gs.dateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),false);
}
I've just added 2 log statements.
After testing it by closing a RITM, please open System Logs -> All and filter so that Message contains '[ritmDuration]' and share the logs

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 02:37 AM
Sorry for the delayed response Dan, my account seemed to have got locked out.
Here are the logs...
The open and close time appears to be the same even though there was 10 minutes between the two.
I've added the 'Closed' field to the form and as soon as the request is raised the date is populated. I've put a watch on the field but nothing is coming up.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 05:09 AM
Thats odd, seems like the closed date is being populated either onLoad of the record (by a client script) or on an insert/update (by a business rule)
It seems incorrect to have a RITM that is not in a closed state to have closed field date populated and this is not OOTB behaviour. Could you check the client scripts/business rules that are running on the sc_req_item table for: 'script' field contains 'closed_at'?