- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 11:14 PM
Hello All,
I have a assignment group in my custom table so when the assignment group is assigned and different assignment group it got assigned i want to calculate time between each assignment group assigned.
Thanks,
Siddu.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 04:58 AM
Hi @siddana Divakar ,
The above requirement needs the metric script .Make sure to adjust the script according to your table and field names and ensure that the metric definition and properties match your specific configuration.
var mi = new MetricInstance(definition, current);
var previousGroup = groupMetric(current.assignment_group);
if (previousGroup != null && !mi.metricExists()) {
var gr = mi.getNewRecord();
gr.start = previousGroup.start;
var now = new GlideDateTime();
gr.end = now;
gr.duration = gs.dateDiff(previousGroup.start, now);
gr.value = current.assignment_group.getDisplayValue();
gr.calculation_complete = true;
gr.insert();
}
function groupMetric(assignmentGroup) {
var metricGR = new GlideRecord('metric_instance');
metricGR.addQuery("definition", "06f9db6d2f94a8101c43bed72799b6c2"); //sys_id of assignment group touch metric
metricGR.addQuery("id", current.sys_id);
metricGR.addQuery("value", assignmentGroup);
metricGR.orderByDesc('sys_created_on');
metricGR.query();
if (metricGR.next()) {
return {
start: metricGR.start,
end: metricGR.end
};
}
return null;
}
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 04:58 AM
Hi @siddana Divakar ,
The above requirement needs the metric script .Make sure to adjust the script according to your table and field names and ensure that the metric definition and properties match your specific configuration.
var mi = new MetricInstance(definition, current);
var previousGroup = groupMetric(current.assignment_group);
if (previousGroup != null && !mi.metricExists()) {
var gr = mi.getNewRecord();
gr.start = previousGroup.start;
var now = new GlideDateTime();
gr.end = now;
gr.duration = gs.dateDiff(previousGroup.start, now);
gr.value = current.assignment_group.getDisplayValue();
gr.calculation_complete = true;
gr.insert();
}
function groupMetric(assignmentGroup) {
var metricGR = new GlideRecord('metric_instance');
metricGR.addQuery("definition", "06f9db6d2f94a8101c43bed72799b6c2"); //sys_id of assignment group touch metric
metricGR.addQuery("id", current.sys_id);
metricGR.addQuery("value", assignmentGroup);
metricGR.orderByDesc('sys_created_on');
metricGR.query();
if (metricGR.next()) {
return {
start: metricGR.start,
end: metricGR.end
};
}
return null;
}
Thanks,
Anand

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 05:58 AM
Hi,
There happens to be Metrics available on the instance for quite a few tables. Give it a check and get one created for the custom table. No need to script.
Metrics >> Definitions from application navigator.
Once done you need to report to get the relevant details.