Return false onSubmit not working on Portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2024 05:39 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2024 05:58 AM
why not use onChange validation and throw error if user is inactive?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2024 08:47 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2024 08:36 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2024 09:06 AM
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.