← Script library

Business Rules

Auto-assign Based on Category

Automatically assign tickets to the appropriate assignment group based on category.

JavaScript
(function executeRule(current, previous /*null when async*/) {

  // Configuration: Map categories to assignment groups
  // Key = category value, Value = assignment group name or sys_id
  var categoryToGroupMap = {
    'hardware': 'Hardware Support',
    'software': 'Application Support',
    'network': 'Network Operations',
    'database': 'Database Team',
    'inquiry': 'Service Desk'
  };

  // Only process if category changed or record is new
  if (current.isNewRecord() || current.category.changes()) {

    var category = current.getValue('category');

    // Check if we have a mapping for this category
    if (categoryToGroupMap[category]) {
      var groupName = categoryToGroupMap[category];

      // Look up the assignment group
      var grGroup = new GlideRecord('sys_user_group');

      // Search by name or sys_id (name shown here)
      grGroup.addQuery('name', groupName);
      grGroup.addQuery('active', true);
      grGroup.setLimit(1);
      grGroup.query();

      if (grGroup.next()) {
        // Set the assignment group
        current.assignment_group = grGroup.sys_id;

        // Optional: Clear assigned_to when changing groups
        current.assigned_to = '';

        // Optional: Add work note
        current.work_notes = 'Auto-assigned to ' + groupName + ' based on category: ' + category;

        gs.info('Auto-assigned incident ' + current.number + ' to group: ' + groupName);
      } else {
        gs.warn('Assignment group not found: ' + groupName + ' for category: ' + category);
      }
    }
  }

})(current, previous);

How to use it

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

Adapt the table names, fields, and conditions to your instance. Test the behavior in a development environment before using it in production.