Skip to content

Commit c1b7643

Browse files
author
SWETHA R
authored
Updated incompleteChkListShowErrMsg.js
1 parent 9a8fe4f commit c1b7643

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
//Business Rule: before update on the incident table
2-
//Condition: changing state to 'In Progress'
1+
// Business Rule: Before Update on Incident table
2+
// Condition: current.state == 2 (In Progress)
3+
34
(function executeRule(current, previous /*null when async*/) {
4-
var checklistGR = new GlideRecord("checklist");
5-
checklistGR.addQuery("document", current.sys_id);
6-
checklistGR.query();
5+
// Only run if state is changing to 'In Progress'
6+
if (current.state == 2 && previous.state != 2) {
77

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

14+
// If any incomplete item exists, abort the action
1415
if (itemGR.hasNext()) {
15-
gs.addErrorMessage('Checklist has incomplete items. Please complete all before assigning it back.');
16+
gs.addErrorMessage("This record has incomplete checklist items. Please complete them before proceeding.");
1617
current.setAbortAction(true);
1718
}
1819
}
1920
})(current, previous);
21+

0 commit comments

Comments
 (0)