Understanding GlideRecord's initialize() Method in ServiceNow: When and How to Use It
- nathanlee142
- Mar 20
- 3 min read
Updated: Mar 29

If you've worked with scripting in ServiceNow, you've likely encountered the GlideRecord class, a powerful way to interact with records in the platform's database. A common source of confusion among developers involves the initialize() method. You may ask yourself, "When should I use gr.initialize() versus simply assigning values directly?"
In this article, we'll clarify what exactly gr.initialize() does, when you should (or shouldn't) use it, and explore some relevant use cases within ServiceNow.
GlideRecord initialize(): Purpose and Common Misunderstandings
At its core, the initialize() method prepares a new record for insertion into a table. This method essentially gives you a clean slate, creating a new, blank instance of the table record that you can populate with values before saving.
Let's examine two scenarios to clearly illustrate its use:
Scenario 1: Using GlideRecord with inbound email actions (No initialize needed)
In ServiceNow inbound email actions, you often see scripts similar to this out-of-the-box (OOB) example:
current.caller_id = gs.getUserID();
current.comments = "Received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.insert();
Notice here there’s no explicit call to initialize(). This is because the current object provided in inbound email actions is already initialized by ServiceNow behind the scenes. You don't need to explicitly initialize it again; the system has already created this record context, ready to accept field assignments.
Scenario 2: Standard GlideRecord scripting (Initialization required)
On the other hand, if you use a standalone GlideRecord script outside predefined contexts (like inbound email actions or record-based UI actions), you must explicitly initialize a new record first. Consider the following code snippet:
var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description = 'New incident created via script';
gr.description = 'This incident was programmatically inserted.';
gr.insert();
In this example, the script explicitly tells ServiceNow, "Create a blank incident record that I will fill with data." If you omit initialize(), the GlideRecord instance might unintentionally retain data from any previously queried records or produce unpredictable results.
Why initialize() Matters: Practical Explanation
When you execute gr.initialize(), you're effectively clearing out the GlideRecord object and starting fresh. This is important because GlideRecord objects can store previous queries or information about existing records. Without initialization, your new record might unintentionally reuse or inherit fields or states, causing data integrity issues or unintended data overwrites.
Therefore, if you're creating new records through direct GlideRecord scripting (such as business rules, scheduled jobs, or script includes), always use initialize() before populating fields and calling insert().
Clarifying Common Confusion: current vs. gr.initialize()
ServiceNow developers often wonder, "Why don't I use initialize() with the current object?" This confusion arises because developers often work in various contexts where the GlideRecord is implicitly provided (like the current object in Business Rules or inbound email actions).
In these scenarios, ServiceNow internally prepares (initializes) the record object for you. Thus, explicitly initializing again is unnecessary and redundant.
Context-provided GlideRecord (current): No initialization needed.
Standalone GlideRecord objects (var gr = new GlideRecord('table')): Initialization required.
Alternative Approach: Using newRecord()
Another useful and often recommended method is newRecord(), which goes a step further than initialize() by not only providing a blank record but also automatically populating fields with their default values as defined in dictionary settings.
Here's how you'd use it:
var gr = new GlideRecord('incident');
gr.newRecord(); // Fields receive default dictionary values automatically
gr.short_description = 'Incident created with defaults';
gr.insert();
Choosing newRecord() over initialize() is especially useful if you rely heavily on predefined defaults to ensure consistent data entry.
Conclusion
Understanding the purpose and usage of GlideRecord's initialize() method is vital for any ServiceNow developer. In summary:
Use initialize() to explicitly prepare a blank record for creation outside of predefined contexts.
You don't need initialize() when using implicitly initialized objects like current in business rules, inbound email actions, or UI actions.
Consider newRecord() when you want to initialize a record and automatically populate fields with default values defined at the dictionary level.
Recommended Next Steps for ServiceNow Developers:
Review your scripts to ensure correct use of initialize() or newRecord().
Test both methods to see their behavior clearly and choose based on your business requirements.
Regularly check ServiceNow documentation or developer resources to stay updated on best practices related to scripting and record manipulation.
By following these best practices, you ensure data integrity, enhance script readability, and optimize the overall stability of your ServiceNow applications.