Auto-assign Based on Category
Automatically assign tickets to the appropriate assignment group based on category.
Table: incident When: before
#auto-assign #assignment-group #category #before #insert #update
Script Code
JavaScript
1(function executeRule(current, previous /*null when async*/) {
2
3 // Configuration: Map categories to assignment groups
4 // Key = category value, Value = assignment group name or sys_id
5 var categoryToGroupMap = {
6 'hardware': 'Hardware Support',
7 'software': 'Application Support',
8 'network': 'Network Operations',
9 'database': 'Database Team',
10 'inquiry': 'Service Desk'
11 };
12
13 // Only process if category changed or record is new
14 if (current.isNewRecord() || current.category.changes()) {
15
16 var category = current.getValue('category');
17
18 // Check if we have a mapping for this category
19 if (categoryToGroupMap[category]) {
20 var groupName = categoryToGroupMap[category];
21
22 // Look up the assignment group
23 var grGroup = new GlideRecord('sys_user_group');
24
25 // Search by name or sys_id (name shown here)
26 grGroup.addQuery('name', groupName);
27 grGroup.addQuery('active', true);
28 grGroup.setLimit(1);
29 grGroup.query();
30
31 if (grGroup.next()) {
32 // Set the assignment group
33 current.assignment_group = grGroup.sys_id;
34
35 // Optional: Clear assigned_to when changing groups
36 current.assigned_to = '';
37
38 // Optional: Add work note
39 current.work_notes = 'Auto-assigned to ' + groupName + ' based on category: ' + category;
40
41 gs.info('Auto-assigned incident ' + current.number + ' to group: ' + groupName);
42 } else {
43 gs.warn('Assignment group not found: ' + groupName + ' for category: ' + category);
44 }
45 }
46 }
47
48})(current, previous);
How to Use
1. Create a before Business Rule on your table
2. Check "Insert" and "Update" checkboxes
3. Customize the `categoryToGroupMap` for your assignment groups
4. Test with various category values
Related Scripts
Send Email Notifications
Send customized email notifications when specific conditions are met.
Populate Fields on Insert
Automatically populate fields with default values or calculated values when a record is created.
Prevent Duplicate Records
Check for existing records and prevent duplicates based on specific field combinations.