Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2019 01:50 PM
In order to better understand what your Business rule is doing, I refactored your code to represent the Incident task query and the Incident modification. Try this in your Business Rule:
(function executeRule(current, previous /*null when async*/) {
var iTask = new GlideRecord('incident_task'); //Find all active child Incident Tasks
iTask.addQuery("incident", current.incident); //Where the incident reference field is the same as current record.
iTask.query("active", true); //and the record is still active
iTask.setLimit(1);
iTask.query();
if (iTask.hasNext()){ //If any open records are found:
gs.addInfoMessage(current.incident.number + " remains open because there are other active Incident Tasks");
} else { //When all records are closed:
var incRec = new GlideRecord("incident"); //Get the parent Incident
if (incRec.get(current.incident)) {
incRec.state = 6;
incRec.close_code = 'Solved (Permanently)';
incRec.close_notes = "Auto-Closed based on Incident Tasks being Closed";
incRec.update();
}
}
})(current, previous);