- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 02:03 PM
Hello,
I need to create a metric definition based on two date fields.
When the AD Review field is changed to "Needed" and saved, a business rule puts the Date/Time in the AD Review Start field:
When the review is completed, the Reviewer changes the AD Review field to Complete. A business rule updates the AD Review End field to the current Date/Time:
I'm trying to create a metric instance using this metric definition which is mostly OOB, and I cannot get it to create the metric. Any ideas?
var end = current.ad_review_end;
if (!end.nil()) {
createMetric();
}
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists()) {
return;
}
var gr = mi.getNewRecord();
gr.start = current.ad_review_start;
gr.end = current.ad_review_end;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}
Thank you,
Laurie
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 09:22 AM
Found it! On the original metric definition I forgot to populate the field AD Review End. Type should be Script Calculation. And then it worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 09:13 PM
Hi @Laurie Marlowe1
Create or Modify the Metric Definition
Navigate to the Metrics module to create a new Metric Definition. Here’s how you get started:
1. Go to System Definition > Metrics.
2. Click New to create a new Metric Definition.
3. Fill in the fields. For your use case, you might do something like the following:
- Name: Name it meaningfully, e.g., “AD Review Duration.”
- Table: Select the table where your “AD Review” changes are recorded.
- Field: This is the field that will trigger the metric. In your case, it seems it’s the “AD Review End” field since you want the duration calculation to start after an end date is recorded.
- Type: Choose “Duration” since you’re measuring the time between two dates.
- Condition: This will define when the metric is recorded. You might set it to look for when “AD Review End” is not empty.
- Start field and End field: Here, specify “AD Review Start” and “AD Review End” respectively.
- Active: Yes.
Remember, the “Type” of the metric being “Duration” is crucial, as it lets ServiceNow know you’re measuring time between two events.
Step 2: Debugging Metric Creation Issues
If the metric instances aren’t being created as expected, here are some troubleshooting tips:
- Ensure Business Rules are Triggering Correctly: Verify that the business rules updating your “AD Review Start” and “AD Review End” fields are functioning as expected. Use the System Log or Debugging tools to check if the rules execute.
- Review Metric Conditions: Double-check the conditions set on the metric definition. The condition must be precise to ensure the metric instance is created only when required.
- Check Access Control: Make sure there aren’t any Access Control Rules (ACRs) preventing the metric from being created. Sometimes, permissions issues can block actions from completing.
- Validate Script Execution: If you are using advanced scripts in your metric definition, ensure they are error-free and logically correct.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
Hello,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 07:17 AM
Hi Deepak,
There are no condition fields on the Metric Definition.
Any other ideas?
Thanks,
Laurie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 11:31 PM
Hi @Laurie Marlowe1 ,
Is the scoped app table an extension of the task table?
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
best regards
Anders…
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 07:15 AM
Hi Anders,
Yes, the scoped app table is an extension of the task table.
Thanks,
Laurie