Problem - Resolved Time

MStritt
Tera Guru

On our Problem form, we have a State field with 3 choices (Open, Work in Progress, Closed). Since we don't have the 'Close Problem' button enabled on the form, when an agent wants to close the Problem they just change the State to Closed. Because of this, the 'Closed' field has no value/date. What I'd ultimately like to do, is have\create an additional field on the Problem table called 'Resolved Time'. This would be the difference between the 'Created value and the 'Closed' value. For this to happen, I need to expose the 'Close Problem' button on the Problem form. When they want to close the Problem, they would click the 'Close Problem' button. This would then place the Closed time in the Closed field. However, if you close the Problem using the 'Close Problem' button, the State does not change to Closed. I need assistance with:

 

1. How do I configure the State to change to 'Closed', if the the 'Close Problem' button is clicked? 

2. How do I configure a new field ('Resolved Time') to calculate the difference between the 'Created' value and the 'Closed' value? Business Rule Advanced script? If so, can you provide sample code?

1 ACCEPTED SOLUTION

Update to the script:

 

var createdOn = current.sys_created_on.getDisplayValue();
var createdDateTime = new GlideDateTime();
createdDateTime.setDisplayValue(createdOn);
var dur = GlideDateTime.subtract(createdDateTime, new GlideDateTime());
current.u_resolved_time = dur;
current.closed_at = new GlideDateTime();

 

View solution in original post

26 REPLIES 26

Okay, so after these three lines you're going to add two lines like below, but update the backend_name... bits with the field name of those two fields you want to set.

current.setValue('backend_name_of_closed_at', nowDate);
current.setValue('backend_name_of_duration_field', dur);

 

Here's what I've configured. Still, when I set the State on a Problem to 'Closed', the Closed (closed_at) field doesn't show a time it was closed. Also, no time in the Resolved Time field.

 

Closed (closed_at)

Created (sys_created_on)

Resolved Time (u_resolved_time)

 

var nowDate = new GlideDateTime();
var openDate = new GlideDateTime(current.sys_created_on);
var dur = GlideDateTime.subtract(openDate, closed_at);
current.setValue('closed_at', nowDate);
current.setValue('u_resolved_time', dur);

 

Before debugging the code, you have the business rule set for "before", but don't have "update" checked off, can you do that and see if that resolves it?

And add a condition for state changes to closed. 

Thanks for your time Kristen.

Made the following updates, but not seeing the Closed field or Resolved Time fields update with a time.

 

MStritt_0-1682025776845.png

MStritt_1-1682025805355.png