Regarding Glide Record method

khuranahima
Tera Contributor

Please clear a doubt.

I tried to insert a record in a table through initialize() method(Glide Record) , using Background Script.

The record was successfully inserted , but when I inserted it without using initialize() method, it was still created.

If we can create a record without initialize() method, then why do we use it?

10 REPLIES 10

Rafael Batistot
Tera Sage

hi @khuranahima

You don’t need initialize() if you are creating a new record and haven’t loaded any existing record.

 


 Use initialize() when:

 

  • You loaded an existing record with .get() or .query(), and now want to create a new record.
  • You want to be safe and clear that you’re creating something new.

 

JackieZhang
Tera Contributor

 initialize() function is used to initialize the record which used for query before such as update and insert logical

Ankur Bawiskar
Tera Patron
Tera Patron

@khuranahima 

it's good practice to use initialize() method.

-> if you reuse a GlideRecord object in a script (such as in a loop or across multiple insert operations) and do not call initialize() between inserts, data you set previously may be unintentionally carried forward into subsequent records

-> This can lead to unintended data duplication or improper population of fields because the object may retain its prior values

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank you !