return false in catalog client script

sanju
Kilo Contributor

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.

1 ACCEPTED SOLUTION

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;
    }
}

 

View solution in original post

12 REPLIES 12

VigneshMC
Mega Sage

Can you share your script ?

Thanks

Mark Stanger
Giga Sage

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.

hi mark.stanger

i have attached the code in the below attachment, kindly verify

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