What It Does
The gs.generateGUID() method creates a random 32-character hexadecimal string that follows GUID standards but omits the typical hyphen separators. The platform uses its internal entropy source to ensure uniqueness across the instance, making collisions statistically impossible within practical usage scenarios.
ServiceNow generates the GUID using the same randomization engine that creates sys_ids for new records, but returns the value as a string rather than assigning it to a database field. The algorithm produces a 128-bit identifier represented as 32 lowercase hexadecimal characters, equivalent to a standard UUID format but compressed without delimiters.
The method always returns a valid 32-character string and never returns null, empty string, or undefined. Each invocation produces a different result, even when called multiple times within the same script execution or transaction. The generated GUID maintains the same entropy quality as platform-generated sys_ids.
Unlike database sys_id generation, generateGUID() operates independently of table constraints, business rules, or ACL evaluations. The method executes quickly with minimal platform overhead since it bypasses database interaction and audit mechanisms entirely.
This method complements other GlideSystem identification methods like gs.generateGUID() for non-database identifiers and gs.getSessionID() for session tracking. The generated GUIDs follow the same character set and length standards as sys_ids but serve different architectural purposes.
When to Use This
Use gs.generateGUID() when you need unique identifiers for correlation across external systems, temporary tracking within script execution, or creating keys for non-persistent data structures. Common scenarios include generating correlation IDs for REST API calls, creating unique identifiers for batch processing operations, or establishing temporary relationships between data elements during complex transformations.
Avoid this method for database record identification where ServiceNow automatically generates sys_ids during insert operations. Use GlideRecord.insert() instead for persistent records, or gs.getSessionID() for session-specific tracking. Never use generated GUIDs as primary keys by manually setting sys_id values, as this bypasses platform integrity mechanisms.
The method works well for creating unique filenames, temporary cache keys, or identifiers in integration scenarios where you control both identifier generation and consumption. Avoid using it for security tokens or cryptographic purposes, as it's designed for uniqueness rather than unpredictability in security contexts.
Return Value
Returns a string containing exactly 32 lowercase hexadecimal characters (0-9, a-f) with no hyphens, spaces, or other delimiters. The format matches the pattern [a-f0-9]{32} and represents a 128-bit value in compact hexadecimal encoding. Examples include values like a1b2c3d4e5f67890abcdef1234567890 or fedcba0987654321abcdef9876543210.
The method never fails or returns error conditions, making it safe to use directly in assignments or concatenations without null checking. The returned string is immediately usable as a JavaScript string with full support for comparison, storage, and manipulation operations.
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, notifications, or workflow activities trigger during GUID generation
- No database writes, audit entries, or journal records are created by this operation
- Execution time is consistently fast (microseconds) with no performance impact from database load or concurrent users
- Works identically across all server-side contexts including Business Rules, Script Includes, Scheduled Jobs, and Transform Maps
- Generated values are not cached or stored by the platform, ensuring each call produces a unique result
- Memory usage is minimal with immediate garbage collection eligibility after the string assignment
- Safe to call in loops or high-frequency operations without platform performance degradation