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

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2009 07:09 AM
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.
- 58,487 Views
11 REPLIES 11
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2024 01:47 AM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2024 05:44 AM
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?