Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Update Incident to be child of first created INC

Tyler Johnson
Kilo Guru

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? 

1 ACCEPTED SOLUTION

Tyler Johnson
Kilo Guru

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);

View solution in original post

2 REPLIES 2

Dr Atul G- LNG
Tera Patron

Hi @Tyler Johnson 

 

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)

*************************************************************************************************************
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/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Tyler Johnson
Kilo Guru

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);