What It Does

The getUniqueValue() method retrieves the sys_id of the record currently loaded in the form. This is the primary key that uniquely identifies the record in the database table. The method directly accesses the form's internal record identifier without making any server calls.

ServiceNow maintains this value in the client-side form context as part of the form's metadata. When a form loads, the platform automatically populates this identifier from the record's sys_id field. The method simply returns this cached value without any processing or validation.

For existing records, this method always returns a 32-character hexadecimal string representing the sys_id. For new records that haven't been saved yet, it returns either null or an empty string, depending on the browser and ServiceNow version. This inconsistency requires defensive coding when checking for new records.

The method behaves identically across all client-side contexts including Client Scripts, UI Policies, and UI Actions. However, the timing of when the sys_id becomes available differs. In onCreate scripts, the value is always empty since the record doesn't exist yet. In onChange and onSubmit scripts for existing records, the value is consistently available.

This method is closely related to g_form.getTableName() which returns the table name. Together, these two methods provide the complete record identifier (table + sys_id) needed for server-side operations like GlideAjax calls or building record URLs.

When to Use This

Use getUniqueValue() when you need to pass the current record's sys_id to server-side scripts via GlideAjax, build URLs to related records, or create reference field values. It's essential for any client-side logic that needs to identify the specific record being viewed or edited. Common scenarios include populating reference fields with the current record, building navigation links, or sending the record ID to custom REST endpoints.

Don't use this method when you need field values from the current record - use g_form.getValue() instead. Avoid using it in onCreate Client Scripts where you're checking if a record is new - use g_form.isNewRecord() for that purpose. Don't concatenate this value directly into URLs without proper encoding, especially in custom applications.

Return Value

Returns a string containing the 32-character sys_id for existing records. The format is always lowercase hexadecimal characters (0-9, a-f) in the pattern xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. For new records that haven't been saved, returns either null or an empty string ''.

Always check for both null and empty string when testing for new records: !g_form.getUniqueValue() handles both cases reliably. The returned string is safe to use directly in GlideAjax parameters, URL construction, and database queries without additional encoding.

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 - this is purely a client-side data retrieval
  • No database queries are triggered - the value is cached in the form context
  • Performance is excellent - immediate return from memory with no network overhead
  • Works identically in all client script types (onLoad, onChange, onSubmit)
  • Value remains constant throughout the form session unless the record is saved for the first time
  • No ACL checks are performed - the sys_id is always accessible if the form loaded
  • Method execution is not logged in system logs or script tracer