
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 06:48 AM - edited 03-12-2024 10:53 AM
Good day!
New metric for when an HR Case is opened until the HR Case hits the awaiting acceptance state?
Thank you for your help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 10:57 AM - edited 03-12-2024 11:10 AM
Hi @Danielle10,
Please find the below screenshot and script that will help achieve this for you (Tried and tested on the HR table on my PDI - Personal Dev Instance).
Please note @Danielle10 - This Metric will only be created when the HR Case is saved in the state of 'Awaiting Acceptance'. (And not before)
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
Screenshot (A new 'Metric Definition')
Script:
// variables available
// current: GlideRecord - target incident
// definition: GlideRecord - (this row)
var s = current.state;
if (s == 20)
createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var hrCaseAwaitAcc = mi.getNewRecord();
hrCaseAwaitAcc.start = current.sys_created_on;
hrCaseAwaitAcc.end = current.sys_updated_on;
hrCaseAwaitAcc.duration = gs.dateDiff(hrCaseAwaitAcc.start.getDisplayValue(), hrCaseAwaitAcc.end.getDisplayValue());
hrCaseAwaitAcc.calculation_complete = true;
hrCaseAwaitAcc.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 07:37 AM
change the table name to HR and add your start time and end time in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 07:23 AM
Hi @Danielle10 ,
You can simply create a Metric Definition with type Field value duration on the State field.
It will capture the duration time whenever the State changes.
Sample below.
For this use case I would either use a (scripted) metric or an SLA Metric if you need to exclude states or have specified work hours that need to be taken into account.
See below for an example scripted metric that comes out of the box:
In the above case the metric is created when a certain state is reached and then calculated from open. You could change that to create a metric from the beginning state and than add the logic to update/complete it when it reaches the end state.
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 08:17 AM
Would you please send me the scripting you typed in your message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 10:57 AM - edited 03-12-2024 11:10 AM
Hi @Danielle10,
Please find the below screenshot and script that will help achieve this for you (Tried and tested on the HR table on my PDI - Personal Dev Instance).
Please note @Danielle10 - This Metric will only be created when the HR Case is saved in the state of 'Awaiting Acceptance'. (And not before)
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
Screenshot (A new 'Metric Definition')
Script:
// variables available
// current: GlideRecord - target incident
// definition: GlideRecord - (this row)
var s = current.state;
if (s == 20)
createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var hrCaseAwaitAcc = mi.getNewRecord();
hrCaseAwaitAcc.start = current.sys_created_on;
hrCaseAwaitAcc.end = current.sys_updated_on;
hrCaseAwaitAcc.duration = gs.dateDiff(hrCaseAwaitAcc.start.getDisplayValue(), hrCaseAwaitAcc.end.getDisplayValue());
hrCaseAwaitAcc.calculation_complete = true;
hrCaseAwaitAcc.insert();
}