Onsubmit client script not working with script include

Sharath807
Tera Contributor

Hi  all Iam trying create display error message on some conditions. When normal onsubmit client script is tried its working fine but , issue was its not working in agent workspace. So i tried with the script include. Now the error message are working fine . But when condition is true is also not able to submit the form. Like if the condition is verified also no error message is displaying also not able to submit the form. Anyone can help

Below is the script:

function onSubmit() {
    var ga = new GlideAjax('UserSelfVerificationStatus');
    ga.addParam('sysparm_name', 'checkVerification');

    ga.getXMLAnswer(function(response) {
        if (response === 'not_verified') {
            var warningMessage = "As the self-verification for your asset is not submitted, you are not allowed to submit this form. " +
                "Please  complete the self-verification.";

            g_form.clearMessages();
            g_form.addErrorMessage(warningMessage);
           
           
            g_form.setSubmit(false);
        }
    });

    return false;  
}
1 ACCEPTED SOLUTION

J Siva
Tera Sage

Hi @Sharath807 

By default GlideAjax doesn't work on the OnSubmit client script.

Please find below docs to know more and workaround.

https://www.servicenow.com/community/developer-blog/how-to-async-glideajax-in-an-onsubmit-script/ba-...

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

Hope this helps.

Regards,

Siva

View solution in original post

2 REPLIES 2

J Siva
Tera Sage

Hi @Sharath807 

By default GlideAjax doesn't work on the OnSubmit client script.

Please find below docs to know more and workaround.

https://www.servicenow.com/community/developer-blog/how-to-async-glideajax-in-an-onsubmit-script/ba-...

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

Hope this helps.

Regards,

Siva

BillMartin
Mega Sage

Hi @Sharath807 ,

 

Sharing with you how Script Includes work in ServiceNow. This lesson will help you build a deeper understanding of how to use Script Includes effectively with object-oriented programming principles. You'll gain full control over the parameters you pass in and the data you return—giving you the confidence and maturity to write clean, reusable, and scalable code.