Query Related to Business Rule

prakharbt20
Tera Contributor

"When an incident is resolved, if it is linked to a problem, the system should check if all other
related incidents are also resolved and then automatically resolve the problem after saving."

 

This is a scenario, How can i do this scenario give me the right code to implement it.

 

Note: Don't tell me the AI-related code.

2 REPLIES 2

TharaS657398130
Kilo Guru

Create a after update Business rule

Condition : State changes to Resolved

 

Script : 

if (current.problem_id.nil()) {
return;
}

 

var p = new GlideRecord('problem');
if (!p.get(current.problem_id)) {
return;
}

 

var i = new GlideRecord('incident');
i.addQuery('problem_id', current.problem_id);
i.addQuery('state', '!=', 6);
i.addQuery('sys_id', '!=', current.sys_id); 
i.query();

 

if (!i.hasNext()) {
p.state = 6
p.close_code = 'Solved (Permanently)';
p.close_notes = 'Auto-resolved as all related incidents are resolved';
p.update();
}

 

Do let me know if you need any explanation of the code

Ankur Bawiskar
Tera Patron

@prakharbt20 

ideally it happens reverse

When PRB is closed then related INCs associated to this PRB are closed

This happens with OOTB BR "SNC - ITIL - Close Related"

Close related Incidents upon closing a Problem 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader