- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2018 04:05 AM
Hi all,
I need to know how to abort action in catalog client script based on the conditions when the catalog item is ordered during the on submit event. Ex if the condition is true i should make a request else if the condition is false i should not be able to make the request. I tried with return false; but it didn't work out well.
any help is really appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2018 06:00 AM
Try this...
function onSubmit() {
var name = g_form.getUniqueValue();
var ga = new GlideAjax('out_of_stock');
ga.addParam('sysparm_name', 'outOfStock');
ga.addParam('sysparm_field', name);
ga.getXMLWait();
var c_name = ga.getAnswer();
alert(c_name);
if (c_name != 'In stock') {
alert('this item is not in stock');
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2018 04:08 AM
Can you share your script ?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2018 04:09 AM
Can you paste your code here so I can look? Really all you should have to do is add 'return false;' to an 'onSubmit' script so the error is probably in the rest of your validation before that point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2018 04:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2018 04:25 AM
The problem is that you're using 'getXML' (which is asynchronous) in an 'onSubmit' client script (which won't wait for your async function to return. If you want to run this validation in an 'onChange' script you'll be fine with the asynchronous 'getXML' call, but if you want to run this validation in an 'onSubmit' script and return false, you'll need to switch to a synchronous 'getXMLWait' for your GlideAjax call as shown here...
https://docs.servicenow.com/bundle/kingston-application-development/page/script/ajax/topic/p_AJAX.html#ariaid-title4