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

nil() vs isNil() - What's the difference?

Chuck Tomasi
Tera Patron

What is the difference between the methods nil() and isNil()? I've seen both used in wiki and forum examples.

Example: Reference Field , http://community.service-now.com/node/1000544

This is where API docs would come in really handy.

11 REPLIES 11

Swarup Patra
Kilo Guru
The methods nil() and isNil() are used in ServiceNow to check if a field or a variable is null or not. Here are the differences between the two: - nil(): - This is a method of the GlideRecord class. - It is used to check if a field in a record is null or not. - It returns true if the field is null or not defined. - It is used in the context of a GlideRecord object. - Example: var gr = new GlideRecord('incident'); gr.query(); if(gr.next()){ if(gr.short_description.nil()){ gs.info('Short description is null'); } } - isNil(): - This is a method of the GlideElement class. - It is used to check if a variable or a field is null or not. - It returns true if the variable or field is null or not defined. - It is used in the context of a GlideElement object. - Example: var gr = new GlideRecord('incident'); gr.query(); if(gr.next()){ if(gr.short_description.isNil()){ gs.info('Short description is null'); } } In summary, both methods are used to check for null values but they are used in different contexts. The nil() method is used with GlideRecord objects while the isNil() method is used with GlideElement objects. nowKB.com
thumb_downthumb_up
 

From CapaJC ServiceNow Employee
ServiceNow Employee
‎09-25-2009 10:36 AM

Looking at the source code, isNil() simply calls nil() and returns its value, so they appear to be identical.

 

So has this changed where context is important?