Error Reference

TypeError: undefined is not a function

TypeError: undefined is not a function

Where this appears

This error appears in ServiceNow system logs, browser console, or script debugger when server-side or client-side scripts attempt to call a method on an undefined variable. It commonly occurs in Business Rules, Script Includes, UI Actions, Client Scripts, and Scripted REST APIs during script execution.

Sourdough
Chrome Extension

Debugging this in a real instance?

Sourdough lets you trace "TypeError: undefined is not a function" through system logs, script errors, and API health in the ServiceNow tab you are already using.

Add to Chrome

Free to install. Pro $5/month after a 14-day no-card trial.
Pro requires the ServiceNow admin role. Upgrade inside the extension.

Overview
Tasks
CMDB
API
Metrics
Monitor
Internals
Instance:sourdoughdev·Version:Yokohama
Instance StateONLINE
System StatusFully Operational
Session Timeout90 minutes
Logged-In Sessions2 (20 active)
Build Nameyokohama-12-18-2024_p1
IP Address10.159.128.43
Instance HealthHealth Score: 90%
🔥 5dSourdough (Chrome Plugin)Dark Mode

Cause

Script Include class or function name is misspelled or the Script Include does not exist in the system. (high likelihood)

GlideRecord query returns no results and script attempts to call methods on the empty result without checking if record exists. (high likelihood)

Function or method name contains a typo when calling built-in ServiceNow API methods or custom functions. (high likelihood)

Script Include is not accessible due to incorrect access scope settings or missing application dependencies. (medium likelihood)

Variable is declared but not initialized before attempting to call a method on it in the script logic. (medium likelihood)

Fix

Step 1: Check the System Log at System Diagnostics > Log > Application Log to identify the exact line number and script where the error occurs.

Step 2: Examine the failing script line to identify which variable or object is undefined when the method is being called.

Step 3: If calling a Script Include, verify it exists in System Definition > Script Includes and check for spelling errors in the class name.

Step 4: For GlideRecord operations, add null checks using if(gr.next()) or if(gr.isValidRecord()) before calling methods on the record object.

Step 5: Verify function names against ServiceNow API documentation and check for typos in method names like getValue(), setValue(), or update().

Step 6: If using Script Includes across applications, check the Accessible from field is set to All application scopes or verify application dependencies are configured.

Step 7: Add defensive coding by checking if variables are defined using typeof variable !== 'undefined' before calling methods on them.

Step 8: Test the corrected script in the Background Scripts module at System Definition > Scripts - Background to verify the fix works.

Test Your Knowledge

Quick 3-question quiz. See how your ServiceNow skills stack up.

Question 1 of 3Performance

A list view on a table with millions of records is slow. Best fix?

Select an answer to continue