What It Does
The getUniqueValue() method retrieves the sys_id field value from the current GlideRecord instance. ServiceNow internally calls the same mechanism as getValue('sys_id') but provides a more semantic method name that clearly indicates you're retrieving the record's unique identifier.
When executed, ServiceNow accesses the current record's field collection and returns the value stored in the sys_id field without performing any additional database queries. The method operates on whatever record is currently loaded in the GlideRecord object, whether that record was retrieved through get(), query() iteration, or represents a new record being created.
The method returns a 32-character hexadecimal string representing the record's GUID when called on a valid, existing record. For new records that haven't been inserted yet, it returns an empty string. If called on a GlideRecord that failed to retrieve any data (such as after an unsuccessful get() call), it also returns an empty string.
The method behaves identically across all GlideRecord states. Whether you're in a Business Rule's current object, iterating through query results, or working with a manually instantiated GlideRecord, getUniqueValue() consistently returns the sys_id of whatever record is currently loaded.
This method pairs naturally with other GlideRecord identification methods. While getUniqueValue() retrieves the sys_id, you'd use getDisplayValue() for human-readable field values and getTableName() to identify which table the record belongs to.
When to Use This
Use getUniqueValue() when you need the sys_id for building relationships, logging, or passing record identifiers to other functions. It's the preferred method for retrieving record IDs in Business Rules, Script Includes, and any server-side code where readability matters. The method name clearly communicates intent, making code easier to understand and maintain compared to the more generic getValue('sys_id') approach.
Avoid using this method when you need display values for user interfaces or when working with reference fields where you want the referenced record's information. Use getDisplayValue() instead for human-readable values. Don't use getUniqueValue() in client-side scripts—GlideRecord works differently there and this method may not be available. For new records before insert(), use isNewRecord() to check record state instead of testing for empty sys_id values.
Return Value
Returns a string containing the 32-character hexadecimal GUID that serves as the record's primary key. The format is always lowercase with no dashes or special formatting—for example, "a1b2c3d4e5f6789012345678901234ab". When the method cannot retrieve a sys_id (such as for new records or failed queries), it returns an empty string "", never null or undefined.
Always check for empty strings when the record's existence is uncertain. Use if (gr.getUniqueValue()) to verify you have a valid record before using the sys_id value. The returned string is safe to use directly in other GlideRecord get() calls, reference field assignments, and database queries without additional encoding or validation.
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 fire when calling this method—it's a pure data retrieval operation
- No database writes occur—the method only reads from the current GlideRecord's field collection in memory
- Extremely fast performance—no database queries are executed, making it safe for loops and frequent calls
- Behaves identically in before/after Business Rules, Script Includes, and Scheduled Jobs—no context-dependent variations
- Values are pulled from ServiceNow's field cache, not re-queried from the database each time
- No audit records are created since this is a read-only operation that doesn't modify field values
- Method is synchronous and blocks execution until the value is returned—no asynchronous behavior or callbacks