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 Amit,

 

Do you have any suggestions regarding my last response?

 

 

Bert_c1
Kilo Patron

Hi @MStritt 

 

As far a using a business rule for your #2, as was suggested by Kristian, I found the following logic to work:

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	gs.info("Problem Duration BR: state = " + current.state + ".");
	var nowDate = new GlideDateTime();
	gs.info("Problem Duration BR: now = " + nowDate + ".");
	var openDate = new GlideDateTime(current.sys_created_on);
	gs.info("Problem Duration BR: open = " + openDate + ".");
	var closedAt = new GlideDateTime(current.closed_at);
	gs.info("Problem Duration BR: closed = " + closedAt + ".");
//	var dur = GlideDateTime.subtract(openDate, closedAt);
	var dur = GlideDateTime.subtract(openDate, nowDate);
	gs.info("Problem Duration BR: now = " + nowDate + ", open = " + openDate + ", dur = " + dur);
	//then use this dur in your time field.
	gs.addInfoMessage('Duration = ' + dur + '.');

})(current, previous);

 

The problem using 'closed_at' is that value is not set when the BR runs (order 100, 'Before'). And since nowDate and openDate are present, the 'dur' field has the difference between the two time values.  The field 'closed_at' does get set (to the same value as nowDate in the script), most likely by another BR or process.  You can add a 'current.u_resolved_time = dur;' at the end of the script.

 

As far as your #1, I don't see the UI action logic here for the 'Close Problem' button. A simple example of that is the UI Action named "Closed" defined on the dmn_demand table.

 

I hope this helps.