
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2019 06:03 PM
Hi,
I saw a OOB Email Inbound Action "Create Incident'' in my developer instance with below script:
current.caller_id = gs.getUserID();
current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.insert();
But when I see the ServiceNow docs for inserting new records in table, I see:
var gr = new GlideRecord('to_do');
gr.initialize();
gr.name = 'first to do item';
gr.description = 'learn about GlideRecord';
gr.insert();
So, for current GlideRecord, is there no need for initialize function?
Then why is gr.initialize() specifically used?
Thanks,
Pranshu
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- 26,400 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2019 06:19 PM
Hi,
To explain a bit more about this, in your first example, that is in an Inbound Action with the action type set to "record action", so that is essentially setting the stage for the new record being inserted already.
In the second example, this is from a glidequery and the system doesn't know what you're about to do...so you're telling it hey...I'd like to create a new record in this table, please give me a blank canvas and I'll paint the picture then insert.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2019 07:19 PM
For what it's worth, I highly recommend looking in to using "newRecord()". While initialize() creates a "space", newRecord() adds to that and sets default values. Goran Lundqvist did a good video on the differences.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2019 11:34 PM
Thanks Chuck, newRecord() in GlideRecord was a new learning for me!