Return false onSubmit not working on Portal.

HrishabhKumar
Kilo Sage

I'm using Async glideAjax in onSubmit catalog client script and allowing the submission of form on the basis of the script include response.

Below code is working for native UI, but not working on portal.

function onSubmit() {
    //Type appropriate comment here, and begin script below
    if (NOW._ajaxChecked) {
        // We have run our Ajax Checks, so we can continue on
        // and let our form submission continue
        NOW._ajaxChecked = null;
        return true;
    }
    var user = g_form.getValue('user');
    g_form.addErrorMessage('check 1');
    var si = new GlideAjax('CheckUser');
    si.addParam('sysparm_name', 'activeOrNot');
    si.addParam('sysparm_user_id', user);
    si.getXMLAnswer(function(ans) {
        g_form.addErrorMessage("ans is: " + ans);
        if (ans == 'false') {
            g_form.addErrorMessage('User is inactive');
            return false;
        }
        NOW._ajaxChecked = true;
        if (typeof g_form.orderNow != 'undefined') {
            // this is a catalog item
            g_form.orderNow();
        } else {
            // this will resubmit the form using the saved 
            // ui action that was originally clicked
            g_form.submit(NOW._action);
        }
    });
return false;
}

 

Don't paste links in the solution, I've already went through lot of articles. I'll appreciate updated code or suggestions.

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@HrishabhKumar 

why not use onChange validation and throw error if user is inactive?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar 

This is a demo code, Actual code contains some complex logic for which I have to use script include. But if this demo code can work, then I'll use the same logic in the actual code as well.

@HrishabhKumar 

did you check this link?

How To: Async GlideAjax in an onSubmit script 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Akshay03
Kilo Sage

Hello @HrishabhKumar ,

Check your methods used in both client script and script include, this is can also cause some issues in portal. (e.g : getDisplaybox)
I'm not sure in your script as you've not pasted original script.