GlideRecord initialize()

Giri6
Tera Expert

I find script includes to generate initialize() automatically and read that it is called as constructor when you create script include the object with a new operator.

Is it not the same for creating new GlideRecord? As initialize() being called for only inserts, I wonder if GlideRecord does not follow the framework being used for script includes and instantiation of this object does not call initialize() automatically.

1 ACCEPTED SOLUTION

ben_knight
Kilo Guru

A bit of speculation below but it seems to make sense.

 

JS didn't add classes with inheritance until ES6 so ServiceNow needed to make their own standardised way of simulating class like behavior. One of the features of a class is a constructor to initialize an object but as they didn't have that they made their own called "initialize".

 

This is completely different in functionality to the GlideRecord "initialize" but as they conceptually do a similar thing they ended up with the same name.

 

View solution in original post

5 REPLIES 5

Yash Agrawal1
Tera Guru

Hello Giri

I hope you know that GlideRecord's initialize method is used to dynamically create a record in the ServiceNow table.

Let's create record in Incident Table.

var record_creation=new GlideRecord('incident');

record_creation.initialize();

record_creation.setValue('short_description','Hello');

record_creation.insert();

This is how you basscially create record.

Just for best practice. always use new record instead of initialize as new record created record with default values.

Please Mark it helpful/correct if my answer helps in any way to resolve your query.
Reach out to me if any more help required.

Regards

Yash.K.Agrawal