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 09:58 PM
Hello Carlo,
Here is the updated 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=='' && pnum=='')
{
g_form.setMandatory('variables.u_owner_group',true);
g_form.addErrorMessage('Owner Group is a mandatory field.');
g_form.setMandatory('variables.purchase_number',true);
g_form.addErrorMessage('Purchase Number is a mandatory field.');
return false;
}
else 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;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 10:10 PM
I have modified the script and it is now working.
function onSubmit() {
g_form.clearMessages();
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.');
}
else if (pnum==''){
g_form.setMandatory('variables.purchase_number',true);
g_form.addErrorMessage('Purchase Number is a mandatory field.');
}
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 10:14 PM
Hello Carlo,
With the script you shared, is this "
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." working fine?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2018 10:32 PM
Yes, Pradeep!
Thanks, Nitesh and Pradeep! Awesome!