Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Metrics to Scoped tables #281

Open
jacebenson opened this issue Apr 6, 2022 · 0 comments
Open

Adding Metrics to Scoped tables #281

jacebenson opened this issue Apr 6, 2022 · 0 comments

Comments

@jacebenson
Copy link
Owner

post: https://community.servicenow.com/community?id=community_question&sys_id=966e14621b824814d01143f6fe4bcbd7

cross scope privledges Target Name: MetricInstance
business rule ```js (function executeRule(current, previous /*null when async*/) {
// Add your code here
queueMetricUpdate();

function queueMetricUpdate() {
var gru = new GlideScriptRecordUtil.get(current);
var fieldsChanged = gru.getChangedFieldNames();
var gr = getDefinitions(fieldsChanged);
fields = '';
while (gr.next())
fields += gr.field + ',';

if (fields.length > 0) {
	fields = '[' + fields.substring(0, fields.length - 1) + ']';
	gs.eventQueue('metric.update', current, fields, current.sys_mod_count, 'metric_update');
}

}

function getDefinitions(fields) {
var gr = new GlideAggregate('metric_definition');
gr.addActiveQuery();
var tables = GlideDBObjectManager.getTables(current.getTableName());
gr.addQuery('table', tables);
gr.addQuery('field', fields);
gr.groupBy('field');
gr.query();
return gr;
}

})(current, previous);

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant