The CreatorCon Call for Content is officially open! Get started here.

Metric Definition - Change ended outside planned window - Script not working, but why?

SB87
Tera Expert

I've scripted the following metric definition against the [change_request] table:

Objective: To record a metric instance if the actual end date/time of a change request is before the planned start date/time or after the planned end date/time.

 

 

var actualEnd = current.work_end;
var plannedStart = current.start_date;
var plannedEnd = current.end_date;

if (actualEnd < plannedStart || actualEnd > plannedEnd)
  createMetric();

function createMetric() {
  var mi = new MetricInstance(definition, current);
  if (mi.metricExists())
    return;

  var gr = mi.getNewRecord();
  gr.end = current.work_end;
  gr.calculation_complete = true;
  gr.insert();
}

 

I've run the following tests, but no change metrics are recorded:

  1. Metric started within planned window but ended outside planned window... No metric recorded
  2. Metric started before planned window and ended after planned window... No metric recorded

Anyone know why? My logic looks correct to me.

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @SB87 

I guess 

actualEnd < plannedStart || actualEnd > plannedEnd)

This is not correct. 

 

Ex:

actualEnd < plannedStart || actualEnd > plannedEnd
18< 15 || 18>19


PS  15th Dec

PE 19th Dec

Actul End 20th Dec

actualEnd < plannedStart || actualEnd > plannedEnd
20 <15|| 20>19

 

See do we have any records like this so check the logic.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

@Dr Atul G- LNG 

What I am trying to account for is:

  1. A change request that ended too soon e.g. it ended on the 15th but shouldn't have even started until the 16th; OR
  2. A change request that ended too late e.g. it ended on the 17th but should have ended by the 16th.

 

actualEnd < plannedStart || actualEnd > plannedEnd)

 

With the above,

 

16th Dec at 5pm < 16th Dec at 1pm || actualEnd > plannedEnd)

 

  • As the actualEnd is less than the plannedStart, then it means it ended before it should have even started, right? i.e. before the planned window.

 

actualEnd < plannedStart || 16th Dec at 8pm > 16th Dec at 7pm)

 

  • As the actualEnd was later than the plannedEnd, then it ended too late.

Since I am using an OR operator, I have tried testing the above with various change records, including one that started before the plannedStart and others that ended after the plannedEnd.

 

Where am I going wrong and what do you propose I should change the logic to? Perhaps I need to use an IF/ELSE? e.g. 

 

if(actualEnd < plannedStart) {
//create metric;
} else if  (actualEnd > plannedEnd) {
//create metric;
else {
return;
}

 

I suppose the other option (although, I prefer not to) is to break this down into two separate metrics...

  1. That checks if a change ended before it was planned to start
  2. Another, where change ended after it was planned to end

Thanks.

Hi @SB87 

 

Try to put the info message to see till what step the script executed.

2. Try with if and else that will be easy

But I am in doubt is is actually  comparing  dates or not. Check this point too.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************