closing all the metric records

Imran4
Tera Contributor

Hi Team,

I am having a requirement in the CSM module. 

I want to capture all the Metric instances when the case state changed from Active to False. So, I have created a Async BR with all the Metric Definitions stored in the property. It is updating all the records sometimes and leaving few records in the very next attempt. The BR wasn't able to update all Metric Instances and leaving the very recently created when the state changes to active to false. I tried Script Include calling from the BR but failed abruptly. I have tried Scheduled Job which will trigger via After BR and it is working totally fine as expected. But my architect isn't allowing me to go through this approach. I have checked all the OOTB things but no luck. It would be great if there is any other way to proceed further or any enhancements are required to fix this issue. Thank you.

9 REPLIES 9

You Have to analysis the when BR is getting failed

 

Can you share your BR details.

 

If it's Not working properly -> you can move to flow.

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Hi @Tanushree Maiti,

Please check my Async Update BR,

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

    var metricProperty = gs.getProperty('AllMetricPropertiesWereIncludedHERE').split(',');
    var grstateMetrics = new GlideRecord('metric_instance');
    grstateMetrics.addQuery('id', current.sys_id);
    //grstateMetrics.addQuery('calculation_complete',false);
    grstateMetrics.addQuery('definition', 'IN', metricProperty);
    grstateMetrics.query();
    while (grstateMetrics.next()) {
        if (grstateMetrics.calculation_complete == false) {
            gs.sleep(10000);
            var startTime = grstateMetrics.start.getValue();
            var endTime = current.getValue('closed_at') || current.getValue('sys_updated_on') || new GlideDateTime().getValue();
            grstateMetrics.end = endTime;
            grstateMetrics.duration = gs.dateDiff(startTime, endTime, false);
            grstateMetrics.calculation_complete = true;
            grstateMetrics.update();
        }
    }

})(current, previous);

BR trigger condition also share please

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Hi @Tanushree Maiti , Please find the attached Screenshot. Thank you.

Screenshot 2026-03-19 184419.png

Nilesh Pol
Kilo Sage

@Imran4 Certainly! Using Flow Designer in ServiceNow is a great way to handle your requirement for updating Metric instances when the Case state changes from Active to False.