calculate Time taken for particular group to approve the Change?

sailajajannu
Kilo Contributor

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

 

3 REPLIES 3

JP - Kyndryl
Kilo Sage

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

 

Regards,
JP

Community Alums
Not applicable

This works! Thank you so much! 

Hi @JP - Kyndryl 

 

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.

 

AysenurU_0-1727788338043.png

For example, here even the weekends have been calculated

 

Thank you ðŸ˜Š