← Script library

Client Scripts

Clear Assignee When Assignment Group Changes

Clear the incident assignee when the assignment group changes on a classic form, so an assignee from the previous group is not carried over accidentally.

JavaScript
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  if (isLoading || isTemplate) {
    return;
  }

  // Also clear the assignee when the assignment group is removed.
  if (g_form.getValue('assigned_to')) {
    g_form.clearValue('assigned_to');
    g_form.addInfoMessage('Assignment group changed. Select an assignee for the new group if needed.');
  }
}

How to use it

1. Create an active onChange Client Script on Incident [incident]. Select Assignment group [assignment_group] as the field and Desktop as the UI Type for a classic platform form. 2. Paste the script. Check existing Client Scripts, assignment rules, and reference qualifiers first; do not install a duplicate if your instance already clears the assignee when the group changes. 3. Load an incident with a group and assignee: both values should remain unchanged. Change the group: Assigned to should clear and an informational message should appear. Remove the group: the assignee should also clear. Change back to the group originally loaded on the form after selecting an assignee: the assignee should clear again (oldValue is the value at form load, not the last selection). 4. Change the group while Assigned to is empty: no message should appear. Applying a template skips this script, preserving template-provided values; validate those combinations separately. 5. This deliberately clears the assignee even if that user belongs to both groups. It does not check group membership or choose a replacement user. Keep an appropriate reference qualifier to limit new assignee selections. 6. This is client-side convenience, not server-side enforcement. Imports, REST writes, and other server-side updates bypass it. UI Builder pages do not run classic Client Scripts. Test other clients separately. 7. To roll back, deactivate this Client Script. It performs no database writes itself; clearing takes effect on the incident only when the form is saved.

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