Metric definition defined but not creating metric instances for sys_updated_by field

Ravi Gupta1
Tera Expert

Metric definition defined but not creating metric instances for sys_updated_by field.

Any suggestion, how to achieve it.

1 ACCEPTED SOLUTION

@Ravi Gupta1 

ServiceNow doesn't monitor OOTB system fields (sys_created_by, sys_updated_by) so metric instances won't trigger unless you add custom logic

use this script in the Metric definition

createMetric(current.sys_updated_by.toString());

function createMetric(value) {
    var mi = new MetricInstance(definition, current);
    var gr = mi.getNewRecord();
    gr.field_value = value;
    gr.calculation_complete = true;
    gr.insert();
}

then have after update business rule on incident table to trigger metric.update event

this will fire the event every time the record is updated allowing your metric definition to create desired metric instances

(function executeRule(current, previous /*null when async*/) {
    gs.eventQueue('metric.update', current, '[sys_updated_by]', 1, 'metric_update');
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Ravi Gupta1 

Is this table a task-based table? If not, then metrics will not work.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi Atul,

Table which I am using is task based. I am able to create metric instance for other fields but not for sys field for same table.

 

Thanks

Ravi

Thanks @Ravi Gupta1 . Could you please try this in the Incident table as an example? Create a new record, then update it and check if the capture is happening or not.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************