What It Does

The getTableName() method returns the string table name that was passed to the GlideRecord constructor when the object was created. This is a simple getter that accesses the internal table reference stored in the GlideRecord instance.

ServiceNow stores the table name as an immutable property when you instantiate the GlideRecord. The method performs no database queries or table validation—it simply returns the string that was originally provided, whether that table exists or not.

The method always returns a string, never null or undefined. Even if you instantiate a GlideRecord with an invalid table name, getTableName() will faithfully return whatever string you provided.

⚠️

For task-extended tables (incident, change_request, sc_req_item), getTableName() returns the table you queried against, not where individual records actually reside. An incident query returns 'incident', even though records might live in tables like incident or problem.

This method differs from getRecordClassName() which returns the actual table where a specific record resides. Both methods serve different purposes: getTableName() tells you what you queried, getRecordClassName() tells you what you found.

When to Use This

Use getTableName() when you need to know which table a GlideRecord object is configured to query against. This is essential for debugging, logging, and generic functions that work with multiple table types. Common scenarios include building dynamic queries, constructing URLs, or validating that you're working with the expected table type.

Do not use this method when you need to determine the actual table where a record is stored—use getRecordClassName() instead. Avoid using getTableName() for record-specific operations on task-extended tables where you need to route logic based on the actual record type.

A common misuse is calling this method unnecessarily in loops or repeated operations. Since the table name never changes for a GlideRecord instance, cache the result in a variable if you need it multiple times within the same scope.

Return Value

Returns a string containing the exact table name used in the GlideRecord constructor. The string is returned as-is with no validation, normalization, or case conversion. If you created the GlideRecord with 'INCIDENT', it returns 'INCIDENT', not 'incident'.

The method cannot fail or return null. Even with invalid table names, empty strings, or malformed input, it returns whatever string was provided to the constructor. You can safely use the return value in string operations without null checks, though you should validate that the table actually exists if that matters for your use case.

Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam · Unsubscribe anytime

Platform Behavior & Side Effects

  • No database queries are executed—this is a pure getter method accessing cached metadata
  • No Business Rules, ACLs, or other platform mechanisms are triggered
  • Performance is instantaneous—the table name is stored as a simple string property
  • No audit trail or logging occurs when this method is called
  • Behavior is identical across all server-side contexts (Business Rules, Script Includes, Scheduled Jobs)
  • Safe to call on empty GlideRecord instances before any queries are executed
  • Return value remains consistent throughout the GlideRecord object's lifecycle