calculate Time taken for particular group to approve the Change?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2022 03:18 AM
Hi All,
I have got a requirement to capture the time taken for an approval group to approve the change. we need to calculate time from the time the Group approval requested to the time It was approved.
Please help me with any of the suggestions .
I have tried running a BR on sysapproval group table and capturing it in duration field . I have taken created and updated field and realize the updated Field is not consistent to get the accurate Data.
Thanks,
sailaja
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2022 07:12 AM
Hi Sailajajannu,
Here's how this be done.
You will need a Metric definition and a Business rule with a script (see attached files).
Here is the script for the BR:
(function executeRule(current, previous /*null when async*/ ) {
var md_sys_id = '9aefa7118774911054c163d73cbb353a'; //change to your sys_id
var definition = new GlideRecord('metric_definition');
definition.get(md_sys_id);
var mi = new MetricInstance(definition, current);
if (current.sys_mod_count > 0)
mi.endDuration();
if (current.getValue('approval') == "requested") {
var gr = mi.getNewRecord();
gr.start = current.sys_updated_on;
gr.field = 'approval,assignment_group';
gr.field_value = current.getValue('approval') + ',' + current.getValue('assignment_group');
gr.value = current.getDisplayValue('approval') + ', ' + (current.getDisplayValue('assignment_group'));
gr.calculation_complete = false;
gr.setWorkflow(false);
gr.insert();
}
})(current, previous);
Once the Metric definition is created, save its sysid and paste it in the script of the BR.
The 3rd attachment is a test result (metric_instance table) I have done in my PDI.
Regards.
JP
JP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 06:29 AM
This works! Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2024 06:13 AM
Thank you very much for the solution. It is working well. However, I have a question. The script calculates all the time including the weekends. How can we add a schedule to this script so that it calculates the 9-5:30PM excluding weekends and holidays etc.
For example, here even the weekends have been calculated
Thank you 😊