← Script library

Business Rules

Prevent Inactive Caller Assignment

Reject new or changed incident callers when the user is inactive or missing, while allowing unrelated updates to incidents with historical inactive callers.

JavaScript
(function executeRule(current, previous) {
  // Configure as a synchronous Before rule: Insert and Update enabled.
  // Leave caller mandatory/optional behavior to existing policies.
  if (current.caller_id.nil()) {
    return;
  }

  // Do not block unrelated edits to historical incidents.
  if (current.operation() !== 'insert' && !current.caller_id.changes()) {
    return;
  }

  var caller = new GlideRecord('sys_user');
  if (!caller.get(current.getValue('caller_id'))) {
    gs.addErrorMessage('The selected caller no longer exists. Select another caller.');
    current.setAbortAction(true);
    return;
  }

  var active = caller.getValue('active');
  if (active !== 'true' && active !== '1') {
    gs.addErrorMessage('Select an active user as the incident caller.');
    current.setAbortAction(true);
  }
})(current, previous);

How to use it

1. In a development instance, create an Advanced Business Rule on Incident [incident]. Set When to Before, enable Insert and Update, and leave Delete and Query disabled. Do not make the rule async. 2. Paste the script. No custom fields, events, or Script Includes are required. Review rule order so the validation runs after any rules that populate caller_id. Do not call current.update(). 3. Test insertion and caller changes with active, inactive, missing, and empty caller values. An inactive or missing selected caller should abort the save with an error. An empty caller is left to your existing mandatory-field policies. 4. Confirm an unrelated update to an existing incident with an inactive caller still succeeds. If all incidents must always have an active caller, use a separate remediation policy rather than blocking historical records here. 5. This is a data-quality guard, not an ACL or a replacement for a reference qualifier. Test integrations and imports with Business Rules enabled; writes using setWorkflow(false) bypass it. Concurrent user deactivation is not locked by this check.

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