Not able to abort submission On Submit Client Script

ramancoder
Tera Contributor

Hi All,

 

Please help me , I won't able to abort the submission on submit client script.

ramancoder_0-1695122920964.png

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var userselected = g_form.getValue('requested_for');
    var ga_html = new GlideAjax('PopulateMobileInstrumentReimbursement');
    ga_html.addParam('sysparm_name''getNoOfDays');
    ga_html.addParam('sysparm_user_sysid', userselected);
    ga_html.getXML(getDetails);

    function getDetails(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
        if (answer < 913.125) {
            alert("Last Reimbursement Claim Date is > 2.5 years then only employees should be eligible for another claim");  
            return false;
        }
    }
}
1 ACCEPTED SOLUTION

Vengateshwaran
Mega Guru

Hi @ramancoder, I have made some changes in your script try now,

function onSubmit() {
 
    if (g_form.isFormValid )
        return true;
    var userselected = g_form.getValue('requested_for');
    var ga_html = new GlideAjax('PopulateMobileInstrumentReimbursement');
    ga_html.addParam('sysparm_name''getNoOfDays');
    ga_html.addParam('sysparm_user_sysid', userselected);
    ga_html.getXML(getDetails);

    return false;

 

    function getDetails(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
        if (answer < 913.125) {
        
            alert("Last Reimbursement Claim Date is > 2.5 years then only employees should be eligible for another claim");  
        return false;
        }else{
g_form.isFormValid = true;
g_form.submit();
return false;
}
    }
}

View solution in original post

3 REPLIES 3

Vishal Birajdar
Giga Sage

Hi @ramancoder 

 

You are using glideajax on onSubmit.

Either you use getXMLWait() method in onSubmit 

OR 

 

Use same code in onChange script may be on Requested for variable ,

store the result in g_scratchpad.

Write onSubmit script , get g_scratchpad value there and depending upon 

g_scratchpad value retur true or false.

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Vengateshwaran
Mega Guru

Hi @ramancoder, I have made some changes in your script try now,

function onSubmit() {
 
    if (g_form.isFormValid )
        return true;
    var userselected = g_form.getValue('requested_for');
    var ga_html = new GlideAjax('PopulateMobileInstrumentReimbursement');
    ga_html.addParam('sysparm_name''getNoOfDays');
    ga_html.addParam('sysparm_user_sysid', userselected);
    ga_html.getXML(getDetails);

    return false;

 

    function getDetails(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
        if (answer < 913.125) {
        
            alert("Last Reimbursement Claim Date is > 2.5 years then only employees should be eligible for another claim");  
        return false;
        }else{
g_form.isFormValid = true;
g_form.submit();
return false;
}
    }
}

Thanks @Vengateshwaran . Code is working fine.