- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 09:07 AM
I want to create a metric on task_sla table. This table contains has_breached field. When ever that field is true, I want to capture the assignment group at that particular time when the SLA is breached.
I have created a metric on Task_sla table and struck up at the scripting part.
Any help is appreciated.
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 05:12 AM
So your getting some data? Change the script to this:
if (current.has_breached == true) {
createMetric();
}
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.value = current.task.assignment_group;
gr.calculation_complete = true;
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 09:43 AM
Read this:
http://wiki.servicenow.com/index.php?title=Metric_Definition_Support#gsc.tab=0
It contains sample scripts. All you need to do is customize an example. Make it run for tasks sla table and change the filter conditions. starting with one of the examples:
set the glide record query to task sla
var gr = new GlideRecord('task_sla')
and query for has breached
gr.addQuery('has_breached', true);
then of course change what you want it to do. Getting assignment group should be easy.
var result = gr.assignment_group // or skip the var
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:13 AM
Hi David,
var gr = new GlideRecord('task_sla');
gr.addQuery('has_breached', true);
gr.query();
while (gr.next()) {
var gs = new GlideRecord('metric_definition');
var result = gr.assignment_group;
Something like the above. Please correct me if I am wrong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:18 AM
Yes your query should run. Although Unless you're using it somewhere else you don't need the gs variable. And you still need to do whatever you wanted to do with the assignment group. gs.addInfoMessage() will display it immediately or gs.log() can send it to a log file. but in what you pasted result is not used. Just to be clear. but it should contain the correct value.
var gr = new GlideRecord('task_sla');
gr.addQuery('has_breached', true);
gr.query();
while (gr.next())
{
var result = gr.assignment_group;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:24 AM
Also If Assignment_group is stored as an ID then adding gr.assignment_group.getDisplayValue() will show you the string you'd expect instead of the long ID value. something like one of these guys "23dc968f0a0a3c1900534f399927740e"