Need client script for validating at least one field is filled in when one field type is a reference and the other is a single line text field

jodyklitzke
Kilo Explorer

I'm currently trying to create a script for validating at least one field is filled on a catalog item.   One field is a reference field and the other is a single line text field.   Here is the script that I'm using:

function onSubmit() {

  if (smcstm_fairview_charge_department == 'NULL' && smcstm_ump_charge_string == '') {

  alert('You must fill in the department code');

  return false;

  }

}

For some reason, it's stopping me from submitting the record.

Any help is appreciated.

1 ACCEPTED SOLUTION

Hello Jody,



Replace your script with the below script and let me know the outcome.


function onSubmit() {


  //Type appropriate comment here, and begin script below


  var chgDep = g_form.getValue('smcstm_fairview_charge_department');


  var umpStg = g_form.getValue('smcstm_ump_charge_string');


  if(!chgDep && !umpStg)


  {


  alert('You must fill in the department code');


  return false;


  }


}



View solution in original post

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Jody,



You need to fetch the input value at client side as


g_form.getValue('PASS NAME OF THE CATALOG VARIABLE HERE');



Reference:


http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#gsc.tab=0


Harsh Vardhan
Giga Patron

Hi Jody,



function onSubmit() {



var test = g_form.getValue('<your reference field>');


if(test=='')


{


return false;


}   }



GlideForm (g form) - ServiceNow Wiki



i tried it in my PDI and it's working. check the screenshot below.



fdsabfjbdavf.png




I hope it will help you.



Thanks,


Harshvardhan




PS: Hit like, Helpful or Correct depending on the impact of the response



Hi Harshvardhan,



I tried the following:


find_real_file.png



It's still not working.


Hello Jody,



Replace your script with the below script and let me know the outcome.


function onSubmit() {


  //Type appropriate comment here, and begin script below


  var chgDep = g_form.getValue('smcstm_fairview_charge_department');


  var umpStg = g_form.getValue('smcstm_ump_charge_string');


  if(!chgDep && !umpStg)


  {


  alert('You must fill in the department code');


  return false;


  }


}