How to stop submission of a form based on the value returned by an asynchronous callback ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 09:30 AM
I have written following code in Catalog Client Script. I want to stop submit record based on the value returned by ValidateAttachment. If ValidateAttachment returns false, I am using return false (to stop submit record). But this is not working as the issue is: Script continues to submit record before the callback returns response.
function onSubmit()
{
var id = '50eebf051bff35501738eb17ec4bcb59';
// var id = g_form.getUniqueValue();
// AJAX call to the server-side script include
var ga = new GlideAjax('NGRPPortalUtilAjax');
ga.addParam('sysparm_name', 'validateAttachment');
ga.addParam('sysparm_app_id', id);
ga.getXML(ValidateAttachment);
}
function ValidateAttachment(response)
{
var answerFromXML= response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answerFromXML);
if(result=='true')
{
alert('Valid Insert' + result);
return true;
}
else
{
alert("Please upload valid format" + result);
return false;
}
}
3 REPLIES 3

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 09:36 AM
I dont think getXML will work. Because it is asynchronous.
You need to use getXMLWait instead.
Please mark this response as correct or helpful if it assisted you with your question.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 09:41 AM
getXMLWait does not work on Service Portal.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 09:46 AM
There is an alternate solution provided in the below article, which may work for service portal.
Please mark this response as correct or helpful if it assisted you with your question.