diff --git a/Server-Side Components/Business Rules/When Group is making inactive/Code.js b/Server-Side Components/Business Rules/When Group is making inactive/Code.js new file mode 100644 index 0000000000..5de78b85db --- /dev/null +++ b/Server-Side Components/Business Rules/When Group is making inactive/Code.js @@ -0,0 +1,30 @@ +(function executeRule(current, previous /*null when async*/) { + + // Run only when group is being inactivated + if (current.active.changes() && current.active == false) { + + var openTicketCount = 0; + + // List of task tables to check + var taskTables = ['incident', 'problem', 'change_request']; + + for (var i = 0; i < taskTables.length; i++) { + var gr = new GlideRecord(taskTables[i]); + gr.addQuery('assignment_group', current.sys_id); + gr.addQuery('active', true); + gr.query(); + if (gr.hasNext()) { + openTicketCount++; + break; // We found at least one open ticket, no need to continue + } + } + + // If open tickets exist, stop the update + if (openTicketCount > 0) { + gs.addErrorMessage('Cannot deactivate "' + current.name + + '" group, because there are open tickets assigned to it.'); + current.setAbortAction(true); + } + } + +})(current, previous); diff --git a/Server-Side Components/Business Rules/When Group is making inactive/ReadMe.md b/Server-Side Components/Business Rules/When Group is making inactive/ReadMe.md new file mode 100644 index 0000000000..06a986ce5c --- /dev/null +++ b/Server-Side Components/Business Rules/When Group is making inactive/ReadMe.md @@ -0,0 +1 @@ +When marking a group as inactive, verify that there are no open tickets assigned to it from 'incident', 'problem', 'change_request' tables. If any open tickets are found, abort the deactivation process.