The CreatorCon Call for Content is officially open! Get started here.

What's the difference between GlideRecord.isNewRecord() and GlideRecord.isValidRecord()?

peterraeves
Mega Guru

What's the difference between GlideRecord.isNewRecord() and GlideRecord.isValidRecord()?

4 REPLIES 4

Lakshmaiah Dump
Giga Expert

Check it out following link



https://www.servicenowguru.com/scripting/client-scripts-scripting/testing-valid-record/




Hit ✅Correct, ��Helpful, or ��Like, Endorsers depending on the impact of the response


@Lakshmaiah Dumpala


Simon Christens
Kilo Sage

isNewRecord() validates true if its validated _before_ insert into the db.


isValidRecord() validates if the record exists in the table (gr) - this can evaluate false even though a given record is not new (is inserted)


Rajesh Mushke
Mega Sage

Hey Peter,



I see the difference between the 2 calls now:



current.isNewRecord() returns true only if the newRecord() method has been called.

current.isValidRecord() returns true if table is valid or if record was successfully fetched, or false if table is invalid or record was not successfully fetched.



Scoped GlideRecord - isNewRecord()


Checks if the current record is a new record that has not yet been inserted into the database.


NameTypeDescription
None
TypeDescription
BooleanTrue if the record is new and has not been inserted into the database.
var gr = new GlideRecord("x_app_table"); gr.newRecord(); // create a new record and populate it with default values gs.info(gr.isNewRecord());


Scoped GlideRecord - isValidRecord()


Determines if current record is a valid record.


NameTypeDescription
None
TypeDescription
BooleanTrue if the current record is valid. False if past the end of the record set.
var rec = new GlideRecord('incident'); rec.query(); while (rec.next()) { gs.info(rec.number + ' exists'); } gs.info(rec.isValidRecord());




Please Refer:


GlideRecord - Scoped


g_form.isNewRecord() gs equivalent




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

johnmunger
Kilo Explorer

The answer is lies in the correction to the question.  Technically, there is no GlideRecord.isNewRecord().  There is only a GlideForm.isNewRecord().  GlideRecords are in the database, so by definition they are not new.  New refers to the state of the Form, hence why it is a GlideForm method.  GlideForm is client side.  GlideRecords are server side.