Giving an error message on submit if any field remains empty on Catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2019 10:52 AM
I tried to write a script to display error message if any fields are empty on submitting catalog item.
function onSubmit() {
if( g_form.getDisplayBox('company').value ==" '' || g_form.getDisplayBox('size').value ==" '' )
{
g_form.addErrorMessage('Please select all the fields');
}
}
But when I test, the error message gets displayed and immediately the page goes to submission confirmation page before the error is resolved.
I want to display the error message and stay on the current page till the error is resolved. After resolving the error, when I try to submit it should go to submission confirmation page.
How can I achieve this criteria?
.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2019 01:15 PM
You don't even need to script set mandatory. On your list layout of variables add mandatory and just set them all to true. This would still not be using UI Policy and be much easier then scripting it.
Also I would go back to the person who gave the requirement and ask why you cannot use UI Polices. Why can I not use the system the way it was meant to be used? Sound like you have someone giving requirements that does not know the system and what it can do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2019 01:33 PM
I will check with them.
I am new to ServiceNow so, may be they want me to explore all possible ways to work on this story.
Thank you, I appretiate your affort to help me out.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2019 11:27 AM
Hi Sam,
Try using below.
function onSubmit() {
alert('Start'); //comment once validated its working
if( g_form.getDisplayBox('company').value ==" '' || g_form.getDisplayBox('size').value ==" '' )
{
alert('in loop');//comment once validated its working
g_form.addErrorMessage('Please select all the fields');
return false;
}
}
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2019 12:05 PM
Hi Jaspal,
Thank you for the response. I have tried it.
The code is working fine with alerts and I am getting error message.
I see that when I click on Order now button after I resolve the error, it is not redirecting me to submission confirmation page.
And also if the condition is false, item is not being able to submit.
I mean No Action is performed when I click on Order Now button in both the cases.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2019 12:33 PM
Hi Sam,
return false; would mean you need to fill the values & click submit again. return false; would just not allow things to be moved if conditions are not satisfied. When the next time you fill the values & click submit the if condition is not satisfied & you are through.
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.