Catalog Client Script Error Message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 09:40 PM
Hi ServiceNow Gurus!
I have a client script that checks if 2 fields are empty. This is my script:
function onSubmit() {
var ogroup = g_form.getValue('u_owner_group');
var pnum = g_form.getValue('purchase_number');
if(g_form.getValue('state')=='3'){
if (ogroup=='undefined' || ogroup==''){
g_form.setMandatory('variables.u_owner_group',true);
g_form.addErrorMessage('Owner Group is a mandatory field.');
return false;
}
else if (pnum==''){
g_form.setMandatory('variables.purchase_number',true);
g_form.addErrorMessage('Purchase Number is a mandatory field.');
return false;
}
}
}
The script above works but I want to modify it because of this "error".
Example 1: I am raising a request and left owner group and purchase number empty. I save the request. The error is "Owner Group is a mandatory field". It does not display "Purchase Number is a mandatory field." error message.
Example 2: When I populate the Owner Group and save the request, "Owner Group is a mandatory field" does not disappear" and "Purchase Number is a mandatory field".
Please help!
Thank you very much.
Carlo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 10:36 PM
Guys, what is the reason why a reference field is returning 'undefined' when the field is empty/null?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 10:19 PM
Hi Pradeep,
The script looks absolutely fine. Just one doubt, shouldn't undefined be without quotes? As 'undefined' is a string.
>> if (ogroup=='undefined' || ogroup==''){

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 10:24 PM
Right and actually speaking at client side it will always return blank so the below statement should be ok.
if (ogroup=='' && pnum=='')

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 10:27 PM
Yes. agreed!