- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 08:38 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2023 07:06 AM - edited ‎04-21-2023 07:07 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2023 12:43 PM
Correct.
Looks like there are previous Problems that have been closed, where there is a date/time in the Closed field (even though the State of the Problem is something other than Closed). Looks like these Problems were closed by making the Active field false. Can we create a fix script that will look at all Problems where there is date/time in the Closed (closed_at) field and calculate the duration, and add that duration value\time in the Resolved Time field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 09:58 AM
Hi @MStritt ,
I trust you are doing great.
- To configure the State field to change to 'Closed' when the 'Close Problem' button is clicked, you can create a new client script on the Problem form that triggers when the 'Close Problem' button is clicked. In the script, you can update the State field value to 'Closed' and then save the form.
Here is a sample code that you can use as a starting point:
(function() {
// Get the Created and Closed values
var created = new GlideDateTime(g_form.getValue('sys_created_on'));
var closed = new GlideDateTime(g_form.getValue('closed_at'));
// Calculate the difference in seconds
var difference = closed.getNumericValue() - created.getNumericValue();
// Create a new GlideDuration object with the difference
var duration = new GlideDuration(difference);
// Set the value of the 'Resolved Time' field to the duration
g_form.setValue('resolved_time', duration.getDisplayValue());
})();
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 10:11 AM
Hi Amit,
I'll go ahead and try that.
How about the 2nd question? If I create a new field called 'Resolution Time', how can I populate a time for that field, which would be the different between Created and Closed times? Once the Problem is closed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 10:20 AM
Nevermind. I see in the sample code that this is configured.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 12:46 PM
Hi Amit,
I've created a new field (Duration) called Resolved Time (u_resolved_time).
I've added the 'Close Problem' button on the Problem form.
I've created a new Client Script on the Problem table (screenshot below).
If I open a Problem that is not closed and is showing the state as 'Work in Progress' and close by clicking on the 'Close Problem' button, the 'Closed' field gets a date/time, but the state of the Problem changes to 'Open' and I don't see any value in the 'Resolved Time' field.
I've configured the Client Script Type for onLoad.