Close Ticket Business Rule [sc_task]

Tracey Wilmot
Tera Contributor

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...

find_real_file.png

find_real_file.png

Any help greatly appreciated.  I would like to do the same for RITMs too.

Many thanks

Tracey

1 ACCEPTED SOLUTION

Dan H
Tera Guru

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

View solution in original post

11 REPLIES 11

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

Back to blank again unfortunately 😞  I really appreciate all of your help with this.

find_real_file.png

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

Sorry for the delayed response Dan, my account seemed to have got locked out.

Here are the logs...

 

find_real_file.png

 

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.

find_real_file.png

 

 

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'?