Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

What's the difference between GlideRecord.initialize() and GlideRecord.newRecord()?

peterraeves
Mega Guru

Basically what the title says. What's the difference between those two functions?

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

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.

 

GlideRecord - ServiceNow Wiki

 

View solution in original post

18 REPLIES 18

Chuck, do you have a video using newrecord() in a widget?


Hi Tim,



We covered initialize() vs. newRecord() on ep 29 of TechNow. There's no reason it shouldn't work in the server script of a widget.



TechNow Episode List


Thank you sir.   I thought I remembered hearing this explained, but could not find it in the 100+(exaggeration) videos I watched on Service Portal.


Thank you for the elaborated response Chuck! It was helpful.

 

Regards,

Hitesh

You are welcome. Thank you for using the community!