‹ All interview questions

Performance

Your production Incident form is loading in 8-10 seconds, impacting user adoption.

The question

Your production Incident form is loading in 8-10 seconds, impacting user adoption. Users report the delay occurs consistently during form load, not on subsequent interactions. You've identified three Business Rules executing on form load, each performing GlideRecord queries. Walk me through your diagnostic approach, explain what's likely causing the slowdown, and show me how you'd optimize this with code examples. What trade-offs would you consider before implementing async rules, and how would you measure improvement?

Why Interviewers Ask This

The 8-10 second load time indicates synchronous processing is blocking the user interface. Business Rules executing during form load are particularly problematic because they're blocking operations—the form won't render until the rule completes. The culprit is likely nested GlideRecord queries without proper filtering, or rules that weren't designed with form load performance in mind.

Your diagnostic approach should start by identifying which rule causes the delay. Enable debug logging, check the session log for execution time, and use browser developer tools to measure network vs. script execution time. This distinguishes between server-side rule delays versus client-side rendering issues.

The Solution

// PROBLEMATIC BUSINESS RULE (Synchronous, Blocking)
if (current.priority == '1') {
  var incidents = new GlideRecord('incident');
  incidents.query();
  while (incidents.next()) {
    var changes = new GlideRecord('change_request');
    changes.query();
    while (changes.next()) {
      if (changes.assignment_group == incidents.assignment_group) {
        current.related_changes = incidents.number;
      }
    }
  }
}
// OPTIMIZED SOLUTION: Extract to Script Include + Async Rule
// Business Rule: async execution
if (current.priority == '1') {
  var processor = new IncidentProcessor();
  processor.linkRelatedChanges(current.sys_id);
}
// Script Include: IncidentProcessor
var IncidentProcessor = Class.create();
IncidentProcessor.prototype = {
  linkRelatedChanges: function(incidentId) {
    var incident = new GlideRecord('incident');
    incident.addQuery('sys_id', incidentId);
    incident.addQuery('priority', '1');
    incident.query();
    if (incident.next()) {
      var changes = new GlideRecord('change_request');
      changes.addQuery('assignment_group', incident.assignment_group);
      changes.setLimit(10);
      changes.query();
      if (changes.next()) {
        incident.related_changes = changes.number;
        incident.update();
      }
    }
  },
  type: 'IncidentProcessor'
};

Senior Considerations

  • Async vs. Sync Trade-offs: Async rules execute after the transaction completes, eliminating form load delays. However, users won't see updated values immediately—use async only when immediate UI feedback isn't required. For critical validations or field updates users expect to see, keep rules synchronous but optimize their execution.
  • Query Optimization: The nested loop pattern is a classic performance killer. Always use addQuery() to filter at the database level before iterating. Limit result sets with setLimit(). Index frequently queried fields like assignment_group and priority.
  • Measurement Strategy: Use ServiceNow's Performance Analytics to measure form load baseline before changes. Track both client and server execution time separately. Set a target of sub-3 second loads; anything over 3-4 seconds frustrates users.
  • setWorkflow(false) Consideration: If your rule updates related records, use setWorkflow(false) to prevent cascading rule triggers, but document this decision—it can mask unintended side effects.
  • Conditional Execution: Wrap rules with specific conditions (current.priority == '1') rather than running on all inserts/updates. This prevents unnecessary execution on records that don't match criteria.
  • Production Validation: Never convert to async without testing user workflows. Some processes depend on synchronous updates completing before subsequent actions. Load test with production-like data volumes—performance issues often surface only under realistic conditions.
  • Monitoring Post-Deployment: Track form load times after optimization. If improvements plateau, investigate client scripts, UI policies, and reference field loads—often the culprit isn't Business Rules alone but their combination with other form components.