Does the metric has a valid until date to stop the metric from being ongoing and executing?

ChuanYanF
Tera Guru

Dear experts,

 

I would like to ask about the metrics, I dont see a valid until date for the metric nor the metric definition. Does ServiceNOW have this kind of feature for metrics? To set the availability and the validity for the metrics. Waiting for your reply, thank you.

3 REPLIES 3

Kieran Anson
Kilo Patron

Hi.

Could you perhaps explain why a metric would need a validity ? The answer to your question is no, but I'd like to understand why you're looking for validity and then offer a more appropriate solution 

Vaisakh Krishna
ServiceNow Employee
ServiceNow Employee

Hi,

There is no valid unto date, however there is an 'Active' field on the metric (and the metric definition). It will not execute once the Active is false. If you set the Active flag on the Metric definition as false, then all the metrics' on the metric definition's Active flag will be set as false.

 

Thanks,

Vaisakh

Hi Vaisakh,

Thanks for the reply, but I have created a scheduled job run that runs daily and this is my script but I think it is still not functioning. May I get some help or advise for my script? Thank you.

(function executeRule(current, gsr) {
    var today = new GlideDate();
    today.setDisplayValue(gs.nowDate()); // 'yyyy-MM-dd' format

    var mdGR = new GlideRecord('sn_grc_metric_definition'); // Replace if using a different table
    mdGR.addQuery('u_valid_until', '<=', today); // Compare u_valid_until <= today
    mdGR.addQuery('active', true); // Only process active records
    mdGR.query();

    while (mdGR.next()) {
        mdGR.setValue('active', false);
        mdGR.update();
        gs.info('Deactivated Metric Definition: ' + mdGR.getDisplayValue('name') + ' due to expired valid_until date.');
    }

})(current, gsr);