The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to call Async function on submit

PriyaVerma
Tera Contributor
 function onSubmit()  
{
   
    var id = '50eebf051bff35501738eb17ec4bcb59';
 
    // 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(ValidatePurchaseDate);
   
}

function ValidatePurchaseDate(response)
{
    var answerFromXML= response.responseXML.documentElement.getAttribute("answer");
    var result = JSON.parse(answerFromXML);
    if(result==true)
    {
        alert('Valid Insert' + result);
        return false;

    }
    else
    {
         alert("Please upload valid format" + result);
         return false;
    }
}
2 REPLIES 2

Jayant_M
Kilo Sage

Hi @PriyaVerma ,

Try result=='true' ,if it does not resolve your issue then please share the script include code?

 

Please mark my answer helpful if it resolves your issue

 

In Script Include, I am checking the format of attachment from sysattachment table, if the format is valid then it returns true else returns false. Now in Client Script, I want to stop submit the record if result of Async function is false. So If result == 'false', message displays "Please upload valid format" and return false (stop submit the record). But this is not working,    

The issue is that since the callback is asynchronous, it does not actually stop the form from being submitted. That's because the script proceeds along to submit the form before the callback has a chance to retrieve the value.