Difference between gs.nil(current.number) and current.number.nil()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2017 10:27 PM
Hi All,
I just want to know the difference between using
gs.nil(current.number) and current.number.nil()
i am able to see the current.number.nil() in wiki but do there any user of ussing gs.nil(current.number) and if there is any can anyone help me understand how they are different. is the 1st one even valid?
Thanks,
Abhinab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2017 10:44 PM
I can say "NO" as far WIKI or docs.servicenow.com.
Thanks,
Vinitha.K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2023 01:33 AM
You can use gs.nil(), JSUtil.nil(), JSUtil.notNil().
Usefull when we don't work on GlideRecords.
Example:
var obj1 = {};
if (gs.nil(obj1["val1"]))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2017 10:47 PM
Hi Abhinab,
GlideSystem has method "nil" that can be used as well to check if passed object is null or empty string. The second case is method of GlideElement's and so you can call it only on GlideElement like "current.caller_id.nil()" but not for other objects - let's say you expect an object being passed into your function and want to check if it was passed, you could then use gs.nil(myOjbect) in your function to check if it is null or empty string.
As gs.nil method is documented also in API so it is valid method to be used.
Best regards,
Dominik

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2019 12:07 AM
Hi
probably the biggest difference is that gs.nil() cannot be used in a scoped application.
But, as Dominik pointed out, the GlideElement methods can only be used on GlideElements ("Columns of a GlideRecord"), not on arbitrary Javascript Objects. Server-side, there is JSUtils.nil() - I do not know the equivalent for client scripts.
Best
Daniel
If this post was helpful, I would appreciate if you marked it as such - thanks!
Best
Daniel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2019 11:16 PM
Hi Daniel,
Thanks for pointing this out. Is it still true for Madrid release? I see gs.nil documented in scoped API on developer site so I would expect it to be working: https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_ScopedGlideSystemNil_Object
Best regards,
Dominik