Metric definition should execute based on condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 03:22 AM - edited 01-15-2024 09:18 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 03:26 AM
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 03:41 AM
Hi Atul,
Thanks for your reply and your YouTube channel.
I have added the code in my question. Please suggest.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2024 04:30 AM
Hi @Asmita7
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]
****************************************************************************************************************