What It Does

The getTableName() method retrieves the table name of the form currently displayed in the browser. When the form loads, ServiceNow stores metadata about the record being viewed, including its table name. This method accesses that cached metadata and returns it as a string value.

The method executes entirely on the client side and requires no server communication. ServiceNow embeds the table name in the form's DOM structure during the initial page load, making this a fast, synchronous operation. The table name is determined when the record is first queried from the database, before any client-side processing begins.

This method always returns the actual table where the record is stored, not any display names or labels. For extended tables, it returns the table name where the specific record resides, which could be either the parent table or the extended table depending on how the record was created. The return value matches exactly what you would see in the sys_class_name field of the record.

The method never returns null or undefined under normal circumstances. If the form somehow lacks table metadata, ServiceNow will typically redirect to an error page rather than allowing the form to load with missing table information. This makes getTableName() one of the most reliable GlideForm methods for defensive programming.

This method complements other GlideForm metadata methods like getUniqueValue() and getSections(). While those methods provide dynamic information about the form's current state, getTableName() provides static metadata that remains constant throughout the form's lifecycle.

When to Use This

Use getTableName() when building shared client scripts that apply to multiple tables. This commonly occurs with global UI policies, client scripts attached to parent tables that affect child tables, or utility functions in script includes that need table-specific logic. The method allows you to branch your code based on the specific table context without hardcoding table names in individual scripts.

Avoid using this method when you're writing table-specific scripts that will only ever run on one table. In those cases, you already know the table name at development time, and hardcoding it makes your intent clearer. Similarly, don't use getTableName() when you need the display name of a table for user-facing messages—use GlideTableDescriptor methods instead.

The most common mistake is using getTableName() to determine field availability instead of using g_form.hasField() or g_form.getControl(). Table extension and field inheritance make table-name-based field detection unreliable compared to direct field existence checks.

Return Value

The method returns a string containing the exact table name as stored in ServiceNow's system dictionary. This string is always lowercase and uses underscores for word separation, following ServiceNow's standard table naming conventions. For example, it returns "incident", "change_request", or "sc_req_item".

The return value is safe to use directly in string comparisons and does not require null checking under normal circumstances. You can safely use it in switch statements, as object keys, or in concatenation operations without defensive coding. The string is encoded in UTF-8 and contains only ASCII characters that are valid in ServiceNow table names.

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 server-side code executes when this method runs—it's purely a client-side metadata retrieval
  • No database operations occur, making this one of the fastest GlideForm methods available
  • The table name is cached in browser memory and remains constant throughout the form session
  • No Business Rules, ACLs, or other server-side logic is triggered by calling this method
  • Works identically in all client script types (onChange, onLoad, onSubmit, onCellEdit)
  • Returns the same value whether the form is in read-only mode, edit mode, or new record mode
  • The value reflects the record's actual storage table, not the form's configured table for extended table scenarios