Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
//Business Rule: before update on the incident table
//Condition: changing state to 'In Progress'
// Business Rule: Before Update on Incident table
// Condition: current.state == 2 (In Progress)

(function executeRule(current, previous /*null when async*/) {
var checklistGR = new GlideRecord("checklist");
checklistGR.addQuery("document", current.sys_id);
checklistGR.query();
// Only run if state is changing to 'In Progress'
if (current.state == 2 && previous.state != 2) {

while (checklistGR.next()) {
// Query checklist items tied to this record that are not complete
var itemGR = new GlideRecord("checklist_item");
itemGR.addQuery("checklist", checklistGR.sys_id);
itemGR.addQuery("complete", false);
itemGR.addQuery("document", current.sys_id); // Matches the current record
itemGR.addQuery("complete", false); // Only incomplete items
itemGR.query();

// If any incomplete item exists, abort the action
if (itemGR.hasNext()) {
gs.addErrorMessage('Checklist has incomplete items. Please complete all before assigning it back.');
gs.addErrorMessage("This record has incomplete checklist items. Please complete them before proceeding.");
current.setAbortAction(true);
}
}
})(current, previous);

Loading