- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2017 11:54 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2017 01:41 PM
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;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2017 12:08 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2017 12:25 PM
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.
I hope it will help you.
Thanks,
Harshvardhan
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2017 01:30 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2017 01:41 PM
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;
}
}