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

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();

 

Bingo. I believe that worked.

 

MStritt_0-1682088444474.png

 

Do you think there's a way to populate the Closed and Resolved Time fields for Problems that have already been closed? And make sure the day/time matches when it was actually closed?

Yes, use a scheduled job/scheduled script execution to do that (set to on demand, so you can run once). You would use GlideRecord to query the records that are missing the data, then loop through them to do that same logic you're doing in the business rule. You'll have to replace the generic new GlideDateTime() that represent "now" with a similar closedOn/closedDateTime using the sys_updated_on (assuming they haven't been updated since closure). while you're figuring out the code in dev, set limit to 1 so that you don't run bad code against all the records. use gs.info to log and validate that you're getting the right records and the right values before you run it against a larger set. remove the gs.info messages before you run against all of them.

Thanks Kristen.

So, we can't use the Closed (closed_at) on the previously closed Problems, because there is no value. We'd have to use the Updated (sys_updated) value instead?

Yes, but I would discuss with the business as to whether that is a valid date to use or if they accept the data only on new records.