The Now Platform® Washington DC release is live. Watch now!
‎07-05-2016 04:11 AM
Basically what the title says. What's the difference between those two functions?
Solved! Go to Solution.
‎07-05-2016 04:15 AM - edited ‎06-29-2023 07:27 AM
Hi Peter,
Per the wiki...
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.
‎07-05-2016 04:15 AM - edited ‎06-29-2023 07:27 AM
Hi Peter,
Per the wiki...
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.
‎07-05-2016 04:28 AM
Hmm, never noticed that. I outputted all variables and it seems that you are correct that inc.initialize() just empties all fields (and puts all default values in it during insert), while inc.newRecord() actually puts the default values in them when called. So it would indeed make more sense to use newRecord instead of initialize. To be fair, it doesn't even make sense to even use initialize after a "new GlideRecord" as all fields are empty at that point anyway.
Thanks for your fast reply!
‎07-05-2016 04:32 AM
You are welcome Peter. I had the same thought when I discovered this. "why would anyone use initialize?", yet everyone does under the assumption that it does what newRecord() does.
‎07-05-2016 04:40 AM
This is definitely going in a future video at some point. I'll be sure to cite your question Peter!