- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2016 04:11 AM
Basically what the title says. What's the difference between those two functions?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2016 04:15 AM - edited ‎06-29-2023 07:27 AM
Hi Peter,
Per the wiki...
- initialize(): Creates an empty record suitable for population before an insert.
- newRecord(); Creates a GlideRecord, set the default values for the fields and assign a unique id to the record.
Try these two in scripts background and you'll see that initialize gives no value to opened_at, whereas newRecord does.
var inc = new GlideRecord('incident');
inc.initialize();
gs.print(inc.opened_at.getDisplayValue());
var inc = new GlideRecord('incident');
inc.newRecord();
gs.print(inc.opened_at.getDisplayValue());
I have always trusted newRecord more since learning about this a few years ago.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2022 10:44 PM
yes because update() insert a new record as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2021 02:34 AM
Here is an additional observation:
For some classes (e.g. sys_db_table_view_field) using newRecord() will even throw errors since some required fields are not populated.
With this in mind, I would now always prefer initialize() over newRecord().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 04:52 AM
@harleyl @Chuck Tomasi Don't you need to use insert() rather than update() after you use newRecord() or initialize()?
Or if not, why is there even an insert() method? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 07:10 AM
var grRecord = new GlideRecord('your_table');
grRecord.initialize();
grRecord.some_field = 'some value';
grRecord.insert();
