What We Did

We integrated a banking API with ServiceNow's catalog system to auto-populate customer account details. When a user enters an account number in a catalog item, the system queries the banking API, retrieves account information (name, type, balance, etc.), and populates the form automatically.

This is a real-world example of synchronous API integration in ServiceNow—useful for any scenario where ServiceNow needs to enrich user input with external data.

The pattern includes:

  • REST Message configuration for API communication
  • GlideAjax for real-time form interaction
  • Script Includes for reusable API logic
  • Multi-type fallback to handle account type variations

How We Did It

Architecture Overview


User enters account number
        ↓
Client script fires onChange
        ↓
GlideAjax calls Script Include
        ↓
Script Include calls REST Message
        ↓
REST Message queries Banking API
        ↓
JSON response comes back
        ↓
Script Include parses and returns data
        ↓
GlideAjax populates form fields

Step 1: REST Message Configuration

Create a REST Message table record:

  • Name: `NC Fiserv` (or your API name)
  • Endpoint: `https://api.bankingservice.com/accounts/inquiry`
  • HTTP Method: POST
  • Auth Type: OAuth (or Basic Auth)

Critical detail: Test the endpoint independently first (via curl or Postman) before wiring it into ServiceNow. This saves debugging time.

Step 2: GlideAjax Client Script

On the catalog item's account_number field, attach an onChange event:


function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || !newValue) return;
  
  var ga = new GlideAjax('FiservAccountLookupAjax');
  ga.addParam('sysparm_name', 'lookupAccount');
  ga.addParam('account_number', newValue);
  ga.getXMLAnswer(function(answer) {
    if (answer == 'false') {
      g_form.clearValue('customer_name');
      return;
    }
    var data = JSON.parse(answer);
    g_form.setValue('customer_name', data.customer_name);
    g_form.setValue('account_type', data.account_type);
  });
}

Step 3: Script Include (AJAX)

Create a Script Include named FiservAccountLookupAjax:


var FiservAccountLookupAjax = Class.create();
FiservAccountLookupAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  lookupAccount: function() {
    var accountNumber = this.getParameter('account_number');
    var service = new FiservAccountLookupService();
    var result = service.queryAccount(accountNumber);
    return JSON.stringify(result);
  }
});

Step 4: Business Logic Script Include

Create FiservAccountLookupService with the actual API call:


var FiservAccountLookupService = Class.create();
FiservAccountLookupService.prototype = {
  queryAccount: function(accountNumber) {
    // Try multiple account types in sequence (DDA, SAV, etc.)
    var types = ['DDA', 'SAV', 'LN', 'SDA', 'CDA', 'LOAN'];
    
    for (var i = 0; i < types.length; i++) {
      var request = {
        account_number: accountNumber,
        account_type: types[i]
      };
      var response = this._callRestMessage(request);
      if (response.account_found) {
        return response;
      }
    }
    return { account_found: false };
  },
  
  _callRestMessage: function(request) {
    var restMsg = new sn_ws.RESTMessageV2('NC Fiserv', 'Post');
    restMsg.setStringParameter('sysparm_input', JSON.stringify(request));
    var response = restMsg.execute();
    return JSON.parse(response.getBody());
  }
};

Step 5: Key Implementation Details

  • Multi-Type Fallback: Loop through account types (`DDA → SAV → LN → ...`) so users only type the account number. The system finds the right type.
  • Response Parsing: Banking APIs sometimes return inconsistent fields. Add fallback logic:
  • 
      var name = response.FullName1 || response.full_name || 'Unknown';
    
  • Error Handling: If the API times out, show a user-friendly message:
  • 
      g_form.addErrorMessage('Account lookup unavailable. Please try again.');
    

Why It Matters

This pattern extends ServiceNow beyond its database boundaries. By integrating external APIs into catalog items, you can:

  • Auto-complete forms with external data (accounts, inventory, pricing)
  • Reduce manual entry errors and support requests
  • Enable real-time validation (is this account active? in good standing?)
  • Build rich workflows that orchestrate across multiple systems

The multi-type fallback is particularly useful in banking and insurance domains where entities have multiple account types.

For teams building service portals, IT ticketing systems, or financial service workflows in ServiceNow, this pattern is the foundation.

Lessons Learned

1. Test the API in isolation first (Postman, curl) before ServiceNow

2. Use dedicated OAuth credentials, not your personal account

3. Add timeout handling for external APIs

4. Log requests/responses for debugging (especially in production)

5. Build fallback logic for inconsistent API responses

This integration can be extended to any REST API—Salesforce, Azure, AWS, custom services—making it a reusable pattern for cross-system automation in ServiceNow.