Notifications

50 views

Description

Symptoms

When a user makes a change within the system and a metric record is generated the "created by" and "updated by" fields are always "system", not the user who actually made the change

Release

All releases

Cause

On the task table, there is a "metric events" business rule which will create a metric.update event. When the event is processed a metric_instance record is created/updated. The metric is processed by "system" and is the reason you see the created by and updated by displayed with "system". This is expected behavior 

Resolution

If you wish to have the metrics displaying the details of the user who initially performed the action which generates/updates the metric you will need to make modifications to the base system

The "metricinstance" script include is responsible for creating an updating all metrics which are type "field value duration" 

https://<INSTANCE>/nav_to.do?uri=sys_script_include.do?sys_id=44c7c3a40a25810200e0dbdf70ea7f0c 

You would need to amend this OOB (Out of Box) script include to manually set the sys_created_on, sys_created_by,sys_updated_on, sys_updated_by and sys_mod_count fields whilst using the GlideRecord autoSysFields(false) when the metric records are inserted/updated. 

Below is an example of a change you could consider which amends the startDuration and endDuration fuctions which are responsible for performing inserts and updates within the metrc_instance table: 

startDuration: function() { 
var gr = this.getNewRecord(); 
gr.field_value = this.current[this.definition.field]; 
gr.start = current.sys_updated_on; 
gr.sys_updated_on = current.sys_updated_on; 
gr.sys_updated_by = current.sys_updated_by; 
gr.sys_created_on = current.sys_created_on; 
gr.sys_created_by = current.sys_created_by; 
gr.sys_mod_count = 0; 
gr.autoSysFields(false); 
gr.insert(); 
}, 

endDuration: function() { 
var gr = new GlideRecord('metric_instance'); 
gr.addQuery('definition', this.definition.sys_id); 
gr.addQuery('id', this.current.sys_id); 
gr.addQuery('calculation_complete', false); 
gr.query(); 
if (!gr.next()) 
return; 

gr.end = this.current.sys_updated_on; 
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue()); 
gr.calculation_complete = true; 
gr.sys_updated_on = current.sys_updated_on; 
gr.sys_updated_by = current.sys_updated_by; 

if (gr.sys_created_on != current.sys_updated_on) 

gr.sys_mod_count = 1; 

gr.autoSysFields(false); 
gr.update(); 
}, 

*Please note this is an example only and you can modify this to meet your specific requirements 

If you do decide to make changes to the base "metricinstance" script include please test thoroughly in a sub-production before implementing in production 

Additional Information

Please note metric definitions which are type "script calculation" use the script field within the definition for the logic of how the record is created. You would need to amend the logic here for each script calculation metric definition to manually populate the system fields sys_created_on, sys_created_by,sys_updated_on, sys_updated_by and sys_mod_count

 

Article Information

Last Updated:2019-08-02 20:39:49
Published:2019-06-19