diff --git a/Server-Side Components/Business Rules/Validate Checklist items/README.md b/Server-Side Components/Business Rules/Validate Checklist items/README.md new file mode 100644 index 0000000000..ff4afbb271 --- /dev/null +++ b/Server-Side Components/Business Rules/Validate Checklist items/README.md @@ -0,0 +1,13 @@ +A business rule that verifies all checklist items are completed before allowing the record to progress to the next status. + +The business rule consists of three main parts: + +Part A: Looks up all checklists (checklist table) tied to the current record (document = current.sys_id). + +Part B: For each checklist, query the checklist_item records: + + Only items in that checklist. + + Only items that are not complete (complete = false). + +Part C: If any incomplete items exist, an error message is displayed and the action is aborted. diff --git a/Server-Side Components/Business Rules/Validate Checklist items/incompleteChkListShowErrMsg.js b/Server-Side Components/Business Rules/Validate Checklist items/incompleteChkListShowErrMsg.js new file mode 100644 index 0000000000..f05bc4dc92 --- /dev/null +++ b/Server-Side Components/Business Rules/Validate Checklist items/incompleteChkListShowErrMsg.js @@ -0,0 +1,19 @@ +//Business Rule: before update on the incident table +//Condition: changing state to 'In Progress' +(function executeRule(current, previous /*null when async*/) { + var checklistGR = new GlideRecord("checklist"); + checklistGR.addQuery("document", current.sys_id); + checklistGR.query(); + + while (checklistGR.next()) { + var itemGR = new GlideRecord("checklist_item"); + itemGR.addQuery("checklist", checklistGR.sys_id); + itemGR.addQuery("complete", false); + itemGR.query(); + + if (itemGR.hasNext()) { + gs.addErrorMessage('Checklist has incomplete items. Please complete all before assigning it back.'); + current.setAbortAction(true); + } + } +})(current, previous);