Unable to submit form after one click on submit button

ashwini  raut
Tera Contributor
Subject: Unable to submit form after one click on submit button 
 
Description: The user has to click on Submit Button 3 times after updating the details to submit the form. If the Submit button is clicked once or twice, the form doesn't get submitted.
 
Issue is with the 2 on submit catalog client script, if we deactivate both the script form is getting submitted in one click only, can you please help here to understand what's went wrong in this script.
 
Script 1 Making some checkboxes mandatory for newzeland user
 
function onSubmit() {
 
// Making the checkboxes mandatory for New Zealand users
    if (g_scratchpad.isFormValid)
        return true;
 
    var gdjUser = new GlideAjax('global.KHCatalogAjaxUtilsNewHire');
    gdjUser.addParam('sysparm_name', 'checkNZUser');
    gdjUser.addParam('sysparm_hrUser', g_user.userID);
    gdjUser.getXMLAnswer(setAnswer);
    return false;
 
    function setAnswer(answer) {
        if (answer == 'false') {
            g_scratchpad.isFormValid = true;
        } else {
            var a = g_form.getBooleanValue('employment_contract_signed_by_employee');
            var b = g_form.getBooleanValue('personal_details_form');
            var c = g_form.getBooleanValue('tax_details_form');
            if (a == false || b == false || c == false) {
                g_form.addErrorMessage("Please check the checkbox for Employment contract signed by employee, Personal details and Tax details");
                return false;
            }
           // var actionName = g_form.getActionName();
            g_scratchpad.isFormValid = true;
            g_form.submit();
        }
    }
}
 
 
Script 2 Making some checkboxes mandatory for austerilia user
 
function onSubmit() {
 
//  Making the checkboxes mandatory for Australia users
    if (g_scratchpad.isFormsValid)
        return true;
 
    var AU = new GlideAjax('global.KHCatalogAjaxUtilsNewHire');
    AU.addParam('sysparm_name', 'checkAUUser');
    AU.addParam('sysparm_hrUser', g_user.userID);
    AU.getXMLAnswer(setAns);
    return false;
 
    function setAns(answer) {
        if (answer == 'false') {
            g_scratchpad.isFormsValid = true;
        } else {
            var a = g_form.getBooleanValue('employment_contract_signed_by_employ');
            var b = g_form.getBooleanValue('personal_details_for');
            var c = g_form.getBooleanValue('tax_file_declaration');
var d = g_form.getBooleanValue('super_form_smsf_attach_compliance_letter');
            if (a == false || b == false || c == false || d == false) {
                g_form.addErrorMessage("Please check the checkbox for Employment contract signed by employee, Personal details, Tax details and Super Form");
                return false;
            }
          //  var actionName = g_form.getActionName();
            g_scratchpad.isFormsValid = true;
            g_form.submit();
        }
    }
}
 
The above 2 causing the issue, But unable to understand the what's going wrong here.
 
Thanks
5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@Ashwini raut Please update your script as follows and see if it works,

 

function onSubmit() {
 
// Making the checkboxes mandatory for New Zealand users
    if (g_scratchpad.isFormValid)
        return true;
 
    var gdjUser = new GlideAjax('global.KHCatalogAjaxUtilsNewHire');
    gdjUser.addParam('sysparm_name', 'checkNZUser');
    gdjUser.addParam('sysparm_hrUser', g_user.userID);
    gdjUser.getXMLAnswer(setAnswer);
    return false;
 
    function setAnswer(answer) {
        if (answer == 'false') {
            g_scratchpad.isFormValid = true;
        } else {
            var a = g_form.getBooleanValue('employment_contract_signed_by_employee');
            var b = g_form.getBooleanValue('personal_details_form');
            var c = g_form.getBooleanValue('tax_details_form');
            if (a == false || b == false || c == false) {
                g_form.addErrorMessage("Please check the checkbox for Employment contract signed by employee, Personal details and Tax details");
                return false;
            }
           var actionName = g_form.getActionName();
            g_scratchpad.isFormValid = true;
            g_form.submit(actionName); 
        }
    }
}

 

function onSubmit() {
 
//  Making the checkboxes mandatory for Australia users
    if (g_scratchpad.isFormsValid)
        return true;
 
    var AU = new GlideAjax('global.KHCatalogAjaxUtilsNewHire');
    AU.addParam('sysparm_name', 'checkAUUser');
    AU.addParam('sysparm_hrUser', g_user.userID);
    AU.getXMLAnswer(setAns);
    return false;
 
    function setAns(answer) {
        if (answer == 'false') {
            g_scratchpad.isFormsValid = true;
        } else {
            var a = g_form.getBooleanValue('employment_contract_signed_by_employ');
            var b = g_form.getBooleanValue('personal_details_for');
            var c = g_form.getBooleanValue('tax_file_declaration');
var d = g_form.getBooleanValue('super_form_smsf_attach_compliance_letter');
            if (a == false || b == false || c == false || d == false) {
                g_form.addErrorMessage("Please check the checkbox for Employment contract signed by employee, Personal details, Tax details and Super Form");
                return false;
            }
            var actionName = g_form.getActionName();
            g_scratchpad.isFormsValid = true;
            g_form.submit(actionName);
        }
    }
}

Hope this change works for you.

@Sandeep Rajput  Thank you for the response.

 

I have tried above changes in my script, Still behavior is same. Its allowing to submit form in 3 click only

Could you please suggest more changes in that if required.

 

Thanks,

Ashwini.

@Ashwini raut Please check the browser console and see if find any errors when you submit the form. 

@Ashwini raut Here is an updated script for you.

 

function onSubmit() {

    //  Making the checkboxes mandatory for Australia users
    if (g_scratchpad.isFormsValid)
        return true;
    var actionName = g_form.getActionName();
    var AU = new GlideAjax('global.KHCatalogAjaxUtilsNewHire');
    AU.addParam('sysparm_name', 'checkAUUser');
    AU.addParam('sysparm_hrUser', g_user.userID);
    AU.getXMLAnswer(setAns);
    return false;

    function setAns(answer) {
        if (answer == 'false') {
            g_scratchpad.isFormsValid = true;
        } else {
            var a = g_form.getBooleanValue('employment_contract_signed_by_employ');
            var b = g_form.getBooleanValue('personal_details_for');
            var c = g_form.getBooleanValue('tax_file_declaration');
            var d = g_form.getBooleanValue('super_form_smsf_attach_compliance_letter');
            if (a == false || b == false || c == false || d == false) {
                g_form.addErrorMessage("Please check the checkbox for Employment contract signed by employee, Personal details, Tax details and Super Form");
                return false;
            }
        }
        g_scratchpad.isFormsValid = true;
        g_form.submit(actionName);
    }
}

Source: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579

 

Hope this helps.