Skip to content

Commit d1e5f97

Browse files
authored
Create Code.js
1 parent c7f2d3a commit d1e5f97

File tree

1 file changed

+30
-0
lines changed
  • Server-Side Components/Business Rules/When Group is making inactive

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(function executeRule(current, previous /*null when async*/) {
2+
3+
// Run only when group is being inactivated
4+
if (current.active.changes() && current.active == false) {
5+
6+
var openTicketCount = 0;
7+
8+
// List of task tables to check
9+
var taskTables = ['incident', 'problem', 'change_request'];
10+
11+
for (var i = 0; i < taskTables.length; i++) {
12+
var gr = new GlideRecord(taskTables[i]);
13+
gr.addQuery('assignment_group', current.sys_id);
14+
gr.addQuery('active', true);
15+
gr.query();
16+
if (gr.hasNext()) {
17+
openTicketCount++;
18+
break; // We found at least one open ticket, no need to continue
19+
}
20+
}
21+
22+
// If open tickets exist, stop the update
23+
if (openTicketCount > 0) {
24+
gs.addErrorMessage('Cannot deactivate "' + current.name +
25+
'" group, because there are open tickets assigned to it.');
26+
current.setAbortAction(true);
27+
}
28+
}
29+
30+
})(current, previous);

0 commit comments

Comments
 (0)