gs.nil() and gs.has() not working in scoped application script.

PVSK
Mega Expert

gs.nil() and gs.has() not working in scoped application script include. What is the alternative other than making JSUtil scope to "all application access".

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Do you want to check whether something is nil or has value then use following

var errorMessage = '';

if(!global.JSUtil.doesNotHave(errorMessage))

{

// something is nil or empty

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi,

According to the Service Now documentation, the scoped equivalent of gs.nil is the .nil() methos of GlideElement:

if ((!current.u_date1.nil()) && (!current.u_date2.nil())) {
  var start = current.u_date1.getGlideObject().getNumericValue();
  var end = current.u_date2.getGlideObject().getNumericValue();
  if (start > end) {
    gs.addInfoMessage('start must be before end');
    current.u_date1.setError('start must be before end');
    current.setAbortAction(true);
  }
}

This has the obvious downside that you cannot apply it to JavaScript Variables.

Best
Daniel


If this answer was helpful, I would appreciate if you marked it as such - thanks!

Best
Daniel

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.

Regards
Ankur

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

The SN Nerd
Giga Sage
Giga Sage

gs.nil() is supported in Madrid


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022