Getting/updating duration of current metric instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2015 07:43 AM
I'm relatively new to ServiceNow, and I'm trying to help set up a custom request task/form. One of the requirements is that it keeps track of how long the request has been in a specific status ("Approved", "For Review", etc.) cumulatively in days and displays it in the form and list layout.
I set up a Metric Definition (field value duration) that runs each time the request status changes and it works like a charm, but I noticed that the last metric instance doesn't have a duration because it hasn't changed or ended yet. My strategy was to try either automatically populating the End Date and/or Duration with the live "now" date/time as long as Calculation Complete is false (so that if the status is changed, the normal metric rules kick in), or to try adding together all the other metric instance durations in the request form field, and then just doing an "if" check like before to calculate the last duration on the fly. And by "automatically", I figure the script fires before displaying the list view of all the requests (similarly to if you click on "Open Incidents").
My questions are: is this a good approach of trying to solve this? And if so, how would this best be implemented? (I've tried messing around with Business Rules, Client Scripts, and Calculated Field Value but my form fields don't get any values; I'm not sure if my scripts aren't firing or if they're not producing any output. The closest I've gotten this to work is with a display business rule, but that requires opening every request form to refresh its value).
Thanks,
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2015 03:03 PM
Simon,
I'm not sure what you mean by adding this new Current Duration field to u_clinical_request_metric. Below is how I set up that database view so far (pretty much only copied the OOB settings from incident_metric):
The calculated field script you provided for Current Duration works great. Will this allow me to potentially add together the Current Duration values of the same ID and same Value into one? For example (below), as a test, CRQ10003 has 3 instances of being set to Approved. Would I be get the total of these values in a "Time Approved" field somewhere that then would have "9 Days 10 Hours 42 Minutes" (based on the sum of the three durations)?
Thanks for your help so far!
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2015 07:36 AM
Hi Chris,
Glad to head the new field is working well. If you can access the new calculated field, you don't need to worry about changing the u_clinical_request_metric view to include your new field. My thought there was about ensuring the calculated field appears everywhere you need it.
I would be tempted to create a new metric definition for the total duration of the request, although you could calculate the total time with the calculated field it would seem a little odd holding this value against the Time Approved metric instance
Simon