What It Does
The getRecordClassName() method returns the actual table name where the current record resides in the database. This becomes crucial when working with table hierarchies where records from extended tables can be retrieved through queries on their parent tables.
Internally, ServiceNow maintains table inheritance through the sys_class_name field on every record in extended tables. When you call this method, it reads that field value to determine which specific table the record belongs to, then returns that table's name as a string.
The method always returns a string containing the table name, never null or empty. If called on a record from a base table with no extensions, it returns the same value as getTableName(). The return value matches exactly what you see in the Table Name field of the table's dictionary record.
An important edge case occurs when working with records that have been moved between tables through table splits or merges. The method still returns the current table name based on the sys_class_name field, which gets updated during these operations.
This method differs fundamentally from getTableName(), which returns the table you queried against. It also differs from getClassName(), which returns the JavaScript class name rather than the database table name.
When to Use This
Use getRecordClassName() when you need to perform different logic based on the specific table type of a record, especially when iterating through results from a base table query. Common scenarios include processing task records where you need different handling for incidents versus changes, or working with configuration item records where behavior varies by CI type.
Avoid this method when you simply need the name of the table you're currently working with - use getTableName() instead. Also avoid it for building queries or API calls where you need the base table name, as those operations expect the parent table name, not the extended table name.
A common misuse pattern involves using this method for table validation or security checks. These should typically use getTableName() instead, since access controls and business rules are usually configured at the base table level.
Return Value
Returns a string containing the exact table name as defined in the database schema. The string is never null, empty, or undefined - even for invalid or deleted records, it returns the table name stored in the record's sys_class_name field.
The returned string can be safely used for string comparisons, building GlideRecord queries on the specific table, or constructing REST API endpoints. However, be cautious when using it to build queries that should include related table types - in those cases, query the base table instead.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.
Platform Behavior & Side Effects
- No business rules, ACLs, or notifications are triggered - this is a simple field read operation
- Nothing is written to the database - the method only reads the existing
sys_class_namefield value - Performance is very fast since it reads from an already-loaded field in memory
- The result is not cached separately - each call reads the field value fresh
- Behavior is identical across all server-side contexts including business rules, script includes, and scheduled jobs
- Works correctly even on records loaded through encoded queries or complex joins
- Returns accurate results even when called multiple times on the same record instance