How to validate glide list field on the client side

jmweli
Kilo Expert

Hi ServiceNow Developers,

 

I am looking for a way if there is one, to check and make sure that there is a value on a glide list field before it is submitted. In other words I am looking for something like getValue() that will check the   value of a field and if the result of getValue() is spaces / empty then I issue an alert / error message and force the users to enter something. Is there a way I can validate the glide list field using client script to check and make sure that there is something on this field before the form is submitted. Please advise.

 

Thanks,

Johannes

1 ACCEPTED SOLUTION

Works as well, should have thought about this earlier


So the modified code would be:


function onSubmit() {
         if (g_form.isNewRecord()){
                   g_form.hideFieldMsg('u_list');
                   if(g_form.getValue('u_list')==''){
                             g_form.showFieldMsg('u_list','List is empty.','error');
                             return false;
                   }
         }
}


Kind regards,


Sascha


View solution in original post

6 REPLIES 6

Works as well, should have thought about this earlier


So the modified code would be:


function onSubmit() {
         if (g_form.isNewRecord()){
                   g_form.hideFieldMsg('u_list');
                   if(g_form.getValue('u_list')==''){
                             g_form.showFieldMsg('u_list','List is empty.','error');
                             return false;
                   }
         }
}


Kind regards,


Sascha


Wow, it works!!



Thank you very much guys, I will replace the business rule that I already have in production with this solution which I think works better because it's client side (before the form gets submitted).



Regards,


Johannes