- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 12:41 PM
Hello ServiceNow,
I have below Metric Defintion script that creates a Metric Instance for incidents opened where user's title is IS SERVICE SPT SRVC DESK TSR 1. This is working as intended however I need to include other titles e.g IS SERVICE SPT SRVC DESK TSR 2, IS SERVICE SPT SRVC DESK TSR 4.
How can I modify the code below to include the other titles?
if (current.opened_by.title == "IS SERVICE SPT SRVC DESK TSR 1") {
var value = true;
createMetric(value);
}
function createMetric(value) {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.field_value = value;
gr.field = null;
gr.calculation_complete = true;
gr.insert();
}
Title field is a string field.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 12:48 PM
Hi,
change the first line as follows:
if ((current.opened_by.title == "IS SERVICE SPT SRVC DESK TSR 1") ||
(current.opened_by.title == "second value") ||
(current.opened_by.title == "third value") ) {
simple javascript 'or' operator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 12:48 PM
Hi,
change the first line as follows:
if ((current.opened_by.title == "IS SERVICE SPT SRVC DESK TSR 1") ||
(current.opened_by.title == "second value") ||
(current.opened_by.title == "third value") ) {
simple javascript 'or' operator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 12:53 PM
Thank you @Bert_c1 this worked. I really appreciate your response and time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2024 06:48 AM
Hi @Mark Nguyen
Could you please send the script include code (metricInstance) which you have used, working with same metric definitions but not showing the metric records. I want to re-verify where I am missing.
Thanks in advance