How to check Reference field empty value in Client script

Supriya25
Tera Guru

Hi All,

When I selected 'None' value in reference field, alert message not coming.

OnChnage Client script
Field : Assignment Group

if(g_form.getValue('assignment_group')==''){

alert('Empty');
}

Supriya25_0-1754438474472.png

 

8 REPLIES 8

Rafael Batistot
Mega Patron

Hi @Supriya25 

 

In ServiceNow, when you’re using an onChange client script for a reference field like assignment_group, the "None" selection (which clears the value) does set the value to an empty string '', just like you’re checking — so your condition is generally correct.

 

However, there are a few reasons why your alert('Empty'); may not be firing:

 

Make sure the client script is set correctly

 

Double-check that:

 

  • Type is: onChange
  • Field is: Assignment Group
  • UI Type: All (or at least the one you’re testing on)
  • Active: ✔️
  • Isolate Script: Leave unchecked (or test both ways)

yes , I'm following very thing. Still alert message not coming. not understanding that is the problem .

  • Type is: onChange
  • Field is: Assignment Group
  • UI Type: All (or at least the one you’re testing on)
  • Active: Supriya25_0-1754441435667.png
  • Isolate Script: TRUE ( tried both)

Chaitanya ILCR
Giga Patron

Hi @Supriya25 ,

in the onChange client script Boilerplate code usually you will get (newValue==='') remove it and check

 

ChaitanyaILCR_0-1754440929275.png

ChaitanyaILCR_1-1754441003136.png

 

if you are still facing the issue please share your entire code here

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

 

without removing (newValue==='')  ,  I tried below two ways , you mean (newValue==='')  will cause it. ?


if(g_form.getValue('assignment_group')==''){

alert('Empty');
}
or 

if(newValue==''){

alert('Empty');
}