Metrics in Scoped Apps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2020 09:41 AM
Hello,
I have a table (doesn't extend Task) in a scoped app that has a "State" field which I want to keep track of time of how long a record spends in each of these states. In the ServiceNow documentation for Metric definitions I found the following:
Note: In the base system, metrics are configured to work on the task table only. To apply metrics to cmdb_ci tables, duplicate the metric events business rule that currently runs on the task table for the cmdb_ci table. Without the events created, no metric processing can occur.
However, when I look at the "metric events" business rule in the Task table, I see that it's inserting an event (metric.update) which is in the global scope. When I then look at the Script Action that runs when that event is inserted, I see that it instantiates an object (script include) called "MetricInstance". This script include is also only available in the Global scope, and the table that it writes to (metric_instance) is ALSO only available in the global scope. I know that a "quick" solution would be to make the table and script include public for other scopes to use, but this is not an option in my case.
Any help would be appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2020 12:26 PM
As you stated, there is an issue with the normal way we add metrics to non-task tables by copying the BR if the new table is scoped. I have gotten it to work for duration metrics (I haven't tested scripted metrics). It requires rewriting the BR, the script action, and the Metric Instance script include. When I rewrote it, I created a new version of each.
The simple solution is to extend task, but if not, it is possible, but a little time-consuming at this point.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 08:01 AM
Adam could you share the specific things you made to get this working?
I can create the Business rule, Script Action, and MetricInstance too, but why do that when I can just ask if you can share the specifics?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2022 05:21 AM
Hi, did you ever get this to work?
I'm in same situation now, but I'm stuck with the copy of the business rule, the GlideScriptRecordUtil class doesnt run in scoped applications.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2022 10:44 PM
I was able to get this to work with help, but It's been a few weeks, where is it failing for you?