How to create metric definition records based on the Catalog Variables in RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 04:30 AM
Hi All,
I want to create "Metric Definition" records based on the value changes in the RITM variables.
Example:
Whenever the state variable changes I want to trigger the record in metric_definition table
Please let me know if any OOB or Customization options to achieve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2024 04:35 AM
Hi @ramesh_r
As per my knowledge you cant create metrics on variable, you can do it only on attribute.
another point
why you created state as variable, when we have state OOTB
Also once a Req submitted why a variable need to change?
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
03-01-2024 10:26 AM
Hi @ramesh_r,
I found your post while researching the same problem and figured out a potential solution, but it does take some interesting scripting. In a nutshell:
- Create a scripted metric on the table you want with an empty script, so essentially a placeholder that wouldn't generate a metric on it's own. Note the sys_id of that defiinition.
- Find the catalog variable on the Options (sys_item_option) table.
- Create a business rule on the Options table for:
- After update (or potentially insert)
- When the question matches the catalog variable.
- When the value is not empty and when the value changes.
- In the script:
- Make sure you have the sys_id for the Metric, the table you want to save it for (probable sc_req_item).
- Create GlideRecords for the Variable Ownership (sc_item_option_mtom) and Requested Item (sc_req_item) tables.
- Get the Variable ownership record where the 'sc_item_option' field is the sys_id of the current record.
- Get the Requested Item record where the sys_id is the value from the 'request_item' field on the Variable ownership record.
- Get the start/end dates and calculate the duration.
- Create a new GlideRecord on the Metrics (metric_instance) table:
- Set the 'table' field to be the correct table to attach the metric.
- Set the 'id' field to be the sys_id of the RITM.
- Set the 'definition' field to be the sys_id for the metric you created.
- Set the 'start' field to be the GlideDateTime of the start for the interval/metric.
- Set the 'end' field to be the GlideDateTime of the end of the interval.
- Set the 'duration' to be the interval from the start to end date.
- If necessary, set the 'business_duration' to be the interval according to your schedule from the start to end date.
- Set the 'calculation_complete' to true.
- Insert the record.
A lot of steps, I moves the manual work to calculate durations and create a metric instance into a script include so I just have to pass the variables instead of hand building it in each metric.
Hope that helps!
Sean