Rafael Batistot
Kilo Patron

Hi @Atik 

 

May you consider a simple business rule

 

Business Rule Setup:

Table: sc_req_item (RITM)

When: after update

Filter condition: state changes to Closed Complete (or any “closed” state you use)

Action: find all related sc_task records and close them.


Code:

(function executeRule(current, previous /*null when async*/) {

// Only run when RITM moves to closed state
if (current.state == 3 && previous.state != 3) { // 3 = Closed Complete

var task = new GlideRecord("sc_task");
task.addQuery("request_item", current.sys_id);
task.addQuery("active", true); // only open tasks
task.query();

while (task.next()) {
task.state = 3; // Closed Complete
task.active = false; // mark inactive
task.work_notes = "Auto-closed because parent RITM was closed (historical load)";
task.update();
}
}

})(current, previous);

 

If this response was helpful, please mark it as Helpful and, if applicable, as Correct, this helps other users find accurate and useful information more easily.

View solution in original post