- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2024 10:20 AM
Im trying to find a solution preferably with flow designer that i can query the Incident table. If there is a record that has a value in the custom field u_uniquefailureid that matches to any other INC that it would then update the oldest or first created INC with the matching id with the newest one being a child INC of the first?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2024 12:43 PM
Was not able to get a flow designer action to work with this but a Business Rule did work.
After Insert
(function executeRule(current, previous /*null when async*/) {
// Only proceed if the current incident has a unique failure ID
if (!current.u_uniquefailureid.nil()) {
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('u_uniquefailureid', current.u_uniquefailureid);
incidentGR.orderBy('sys_created_on'); // Ensure oldest is first
incidentGR.query();
var firstRecord = true;
var oldestRecordSysId = '';
while (incidentGR.next()) {
if (firstRecord) {
oldestRecordSysId = incidentGR.sys_id.toString();
firstRecord = false;
} else if (incidentGR.sys_id == current.sys_id) {
// When we reach the current record, if it's not the first one, set its parent_incident
if (!oldestRecordSysId.equals(current.sys_id.toString())) {
current.parent_incident = oldestRecordSysId;
current.update(); // Update the current incident to set the parent_incident field
}
break; // No need to continue looping once we've found and updated the current record
}
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2024 10:34 AM
I dont have solution for this, but ootb, if a child incident added then if any action done on parent will applied to child as well (with some specific state)
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-13-2024 12:43 PM
Was not able to get a flow designer action to work with this but a Business Rule did work.
After Insert
(function executeRule(current, previous /*null when async*/) {
// Only proceed if the current incident has a unique failure ID
if (!current.u_uniquefailureid.nil()) {
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('u_uniquefailureid', current.u_uniquefailureid);
incidentGR.orderBy('sys_created_on'); // Ensure oldest is first
incidentGR.query();
var firstRecord = true;
var oldestRecordSysId = '';
while (incidentGR.next()) {
if (firstRecord) {
oldestRecordSysId = incidentGR.sys_id.toString();
firstRecord = false;
} else if (incidentGR.sys_id == current.sys_id) {
// When we reach the current record, if it's not the first one, set its parent_incident
if (!oldestRecordSysId.equals(current.sys_id.toString())) {
current.parent_incident = oldestRecordSysId;
current.update(); // Update the current incident to set the parent_incident field
}
break; // No need to continue looping once we've found and updated the current record
}
}
}
})(current, previous);