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

Hi Kristen,

 

How do I configure the calculated time to be put in the new Resolution Time field? In the BR? Added to the code you provided above?

Yes, I would create a business rule, make it advanced, and then put the code in the script field. You'll need to add a line (where the comment is) to set the resolution time field to the duration found.

I created the following BR using the code you provided. However, when I select Closed as a Problem State and Save, the Closed field (closed_at) doesn't have any value in it.

 

MStritt_2-1682011425102.png

 

 

MStritt_0-1682011278083.png

MStritt_1-1682011313831.png

 

Also, if you can provide sample code for the line that will populate the calculated time in the new field (u_resolved_time), that would be helpful. Don't have a lot of experience with coding/scripting.

 

You could add that into your code, just set closed at to the nowDate.

Not sure I'm following.  Change nowDate to closed_at? This didn't add a time in the Closed field when I closed a Problem.

var nowDate = new GlideDateTime();
var openDate = new GlideDateTime(current.sys_created_on);
var dur = GlideDateTime.subtract(openDate, closed_at);
//then use this dur in your time field.