Metric Definition Script to exclude weekends

andrewdunn
Giga Expert

Team - I have a metric set up in our change table to record the time between the end date of the change and when it is closed. Creating the metric has improved our Change Manager's ability to manage compliance, however they have identified that time over a weekend should not be included - ie if a change finishes at 1PM on Friday and is closed at 1 PM on the following Monday it should capture 1 day (24 hours)

Is anybody able to assist - below is the current code working as initially requested:

Cheers

if (current.state == 3)
  createMetric();
 
if (current.state == 4)
  createMetric();
 
function createMetric() {
  var mi = new MetricInstance(definition, current);
  if (mi.metricExists())
    return;
  var gr = mi.getNewRecord();
  gr.start = current.work_end;
  gr.end = current.closed_at;
  gr.duration = gs.dateDiff(gr.start, gr.end);
  gr.calculation_complete = true;
  gr.insert();
}
1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Use case 2.1 should help you in below blog

 

https://community.servicenow.com/community?id=community_blog&sys_id=467c62e1dbd0dbc01dcaf3231f9619ad

 

You can use a schedule and set your work end time.


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

1 REPLY 1

SanjivMeher
Kilo Patron
Kilo Patron

Use case 2.1 should help you in below blog

 

https://community.servicenow.com/community?id=community_blog&sys_id=467c62e1dbd0dbc01dcaf3231f9619ad

 

You can use a schedule and set your work end time.


Please mark this response as correct or helpful if it assisted you with your question.