What It Does
The initialize() method completely resets a GlideRecord object to its initial state, as if you had just created a new instance. It clears all field values that have been set, removes any query conditions that were added, and resets the internal state to prepare for a fresh operation. This is particularly important because GlideRecord objects retain field values even after calling insert() or completing other operations.
Internally, ServiceNow clears the object's field value cache, resets the row state indicators, and removes any query filters or ordering that was previously applied. The GlideRecord maintains its table reference but loses all data context. This reset is more thorough than simply setting individual fields to empty values because it also clears internal flags that track which fields have been modified.
The method returns void and never fails. There are no error conditions because it's simply clearing memory structures rather than performing database operations. The operation is instantaneous and always succeeds, making it safe to call at any time without error handling.
One edge case involves extended tables with inherited fields. The initialize() method clears all field values including those from parent tables, but the GlideRecord still maintains its table context. If you had a GlideRecord pointing to the incident table, after initialize() it will still be an incident GlideRecord, just with no field values set.
The method differs from newRecord() in that initialize() works on an existing GlideRecord object, while newRecord() immediately creates a new database record. Both prepare for inserts, but initialize() is purely a memory operation.
When to Use This
Use initialize() when you're reusing a GlideRecord object for multiple insert operations, especially inside loops. Without calling initialize(), field values from previous iterations will carry over to subsequent inserts, creating records with unintended data. This is the primary use case and the reason most developers encounter this method.
Avoid initialize() when you're only performing a single insert operation—just create a new GlideRecord instance instead. Don't use it to 'reset' a GlideRecord for queries; create a new GlideRecord object for query operations. A common mistake is calling initialize() before every operation as a 'safety measure'—this adds unnecessary overhead when you could simply instantiate new objects.
Return Value
The method returns void (undefined in JavaScript), meaning it doesn't return any value. The method modifies the existing GlideRecord object in place rather than returning a new object or status indicator. You don't need to capture or check any return value from this method.
Since the method cannot fail, there's no error state to handle. The operation always succeeds and leaves the GlideRecord object in a clean, predictable state ready for new field assignments and subsequent insert 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, or workflows are triggered since this is purely a client-side memory operation
- No database operations occur—nothing is written to or read from the database
- Extremely fast performance—only clears memory structures with no I/O operations
- No audit trail entries are created since no data changes occur on the platform
- Behaves identically across all server-side contexts—Business Rules, Script Includes, Scheduled Jobs
- Clears any pending insert operations that were prepared but not yet executed
Field values are cleared completely, not set to default values. After initialize(), all fields return empty/null values regardless of any default values defined on the table.