Duration of State with respect to assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hi All,
I have a requirement to calculate the state of the Sc_task record with respect to the assignment group.
For example- A sc_task was assigned to Service desk and they keep it on open state for 2 hours then move it to Data center group and then they keep it for open state for 1 hour and 3 hour in work in progress state.
So i want the 3 individual records in Metric table....that will give me the insight that this assignment kept this task on XYZ duration.
Please let me know, if some can help me on this??
Also can this be achieve in Metric definition?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hi
It is possible using metric definitions
1. Create a new metric definition for group field
Paste below code and updated metric definition sysid highlighted in the code
Paste the script and update the metric definition sysid highlighted in code below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
Hi @AryanSingh
There are 2 options:
Option1 : If you need to display this information directly on the task form or in a report that includes fields from sc_task , you can create a database view on sc_task ( refer OOB database view incident_metric)
Refer: Calculating task states
Option2: Create a custom metric definition
- Navigate to Metrics > Definitions.
- Click New.
- Fill in the form:
- Name: SC Task Group State Duration
- Table: Catalog Task
- Field: state or assignment group as per your requirement
Sample script/ Not tested:
var grMetric = new GlideRecord('metric_instance');
var definitionName = 'SC Task Gr State Duration'; // Replace your Metric Name
grMetric.addQuery('definition.name', definitionName);
grMetric.addQuery('id', current.sys_id);
grMetric.addQuery('calculation_complete', false);
grMetric.query();
if (grMetric.next()) {
if (grMetric.field_value != current.assignment_group.getDisplayValue() + ' - ' + current.state.getDisplayValue()) {
grMetric.calculation_complete = true;
grMetric.end = current.sys_updated_on;
grMetric.duration = gs.dateDiff(grMetric.start, grMetric.end, true);
grMetric.update();
createInstance();
}
} else {
createInstance();
}
function createInstance() {
var newgrMetric = new GlideRecord('metric_instance');
newgrMetric.initialize();
newgrMetric.definition = definition;
newgrMetric.id = current.sys_id;
newgrMetric.table = 'sc_task';
newgrMetric.field_value = current.assignment_group.getDisplayValue() + ' - ' + current.state.getDisplayValue();
newgrMetric.start = current.sys_updated_on;
newgrMetric.calculation_complete = false;
newgrMetric.insert();
}
