Parent field on metrics record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 10:27 AM
Hello Experts,
We have metrics on Incident Task table for state field. And metrics records are created whenever the 'state' is changed. On the metrics record I see incident task number on 'ID' field. But, We also want to display the 'Incident' number on that metrics record and since 'ID' field is document id type, I couldn't dot walk it.
How can I achieve this?
Thanks,
Rocky.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 10:50 AM
Hi @Rocky5 ,
Based on your requirement, you can follow the below approach, I've listed it step by step, follow that and see if it works:
Create a Custom Field on the Metric Table: Add a new field to the Metric table to store the 'Incident' number.
Create a Business Rule on the Metric Table: Use a business rule to populate this custom field whenever a metric record is created or updated.
Here I'm providing the detailed steps:
Step 1: Add a Custom Field to the Metric Table
- Navigate to the Metric table.
- Add a new field (e.g., incident_number) to the Metric table of type String .
Step 2: Create a Business Rule on the Metric Table
Navigate to the Metric table's business rules.
Create a new business rule with the following settings:
- When to Run:
- When: Before
- Insert: True
- Update: False (since metrics are usually not updated but only created)
- Conditions:
- [Any condition if needed, e.g., Type is 'State Change']
- Advanced: True
- When to Run:
(function executeRule(current, previous /*null when async*/) {
// Ensure the metric is related to an Incident Task
if (current.table == 'incident_task') {
// Fetch the related Incident Task record
var incidentTaskGR = new GlideRecord('incident_task');
if (incidentTaskGR.get(current.id)) {
// Get the Incident related to this Incident Task
var incidentNumber = '';
if (incidentTaskGR.parent) {
var incidentGR = new GlideRecord('incident');
if (incidentGR.get(incidentTaskGR.parent)) {
incidentNumber = incidentGR.number;
}
}
// Set the Incident number in the custom field
current.u_incident_number = incidentNumber;
}
}
})(current, previous);
Thanks,
Hope this helps.
If my response proves helpful please mark it helpful and accept it as solution to close this thread.