Metric definition should execute based on condition

Asmita7
Tera Expert

Hi friends,

 

I am creating a metric definition to capture a field value "u_enroll_date".

Requirement is that the field change should be captured only when the "state" field changes to "Delivered." For other "state" field values it should not capture the "u_enroll_date".

 

Code :

var Req = current.state;
if (Req == 'delivered' || Req == 'Delivered') {          //// This condition is not working. 
createMetric();
}

function createMetric() {
var mi = new MetricInstance(definition, current);
var gr = mi.getNewRecord();
gr.value=current.sys_updated_by;
gr.insert();
}

 

The Condition in RED above is not working. It is creating record in metric every time the state is changes. It should capture only when the state is Ordered.

How to achieve it through metric script. I cannot add this condition to metric definition business rule since it is required for some other fields as well.

 

Thank you

 

 

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Asmita7 

 

Did you try any code ? If yes please share so that we can help you. More you try handson, more quickly you learn. 

*************************************************************************************************************
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]

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

Hi Atul,

 

Thanks for your reply and your YouTube channel.

 

I have added the code in my question. Please suggest.

 

Thank you

Hi @Asmita7 

 

https://www.servicenow.com/community/developer-forum/incident-quot-assigned-to-quot-metric-by-quot-s...

 

Some baseline info.

 

@Anurag Tripathi @Ankur Bawiskar  support here. 

*************************************************************************************************************
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]

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