The Zurich release has arrived! Interested in new features and functionalities? Click here for more

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

Hi @Supriya25 ,

if you have something like this in your code

when the group value is empty it will hit the return statement and other line will not run

ChaitanyaILCR_0-1754442803706.png

 

you convert it to something like this

ChaitanyaILCR_1-1754442930920.png

 if (!newValue) {
        alert('EMPTY');
    }

 

 

please share you code and client script screenshots if you are still facing the issue

 

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

Regards,
Chaitanya

 

Bhuvan
Kilo Patron

@Supriya25 

 

Try removing this section and test it,

Bhuvan_0-1754443382966.png

Below is a test client script,

Bhuvan_1-1754443422958.png

 

Bhuvan_2-1754443464595.png

Thanks,

Bhuvan

kaushal_snow
Mega Sage

Hi @Supriya25 ,

 

To detect when a reference field such as Assignment Group has been cleared (i.e. set to “ None ”), ensure your onChange client script does not exit when newValue === ''; instead, remove that condition so if (g_form.getValue('assignment_group') == '') { alert('Empty'); } will successfully trigger the alert.

 

Try this once and let me know. If you find this helpful, please accept this as a solution and hit the helpful button..

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Ankur Bawiskar
Tera Patron
Tera Patron

@Supriya25 

if it's a reference field then why it's showing None option and why it's a drop down?

what type of field is that? share screenshots

what's your business requirement?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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