- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2019 06:00 AM
I have a client side script that is supposed to validate some values on the catalog item page during Submit event, and to stop submit if it fails. The problem comes in during validation because Ajax call is also involved there, and we all know that we can't stop submit from within Ajax callback. The solution for this frequent issue is described here: https://snprotips.com/blog/2018/10/19/synchronous-lite-onsubmit-catalogclient-scripts . Basically a flag is set inside the Ajax callback and the form gets re-submitted if valid, something like this:
function onSubmit() {
if (getValueOfTheFlag('valid')) {
return true;
}
var gAjax = new GlideAjax('MyUtil');
gAjax.getXML(MyCallBack);
return false;
}
function MyBallBack(response) {
if(response.success) {
setValueOfTheFlag('valid', true);
g_form.submit();
} else {
setValueOfTheFlag('valid', false);
}
}
The problematic line here is g_form.submit() call, which is supposed to resubmit the form after validation, however when that line is executed, I get this error message:
Solved! Go to Solution.
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2019 11:15 AM
Thank you, but I just wanted to re-submit the form in order to keep the same UI experience. Turns out g_form.getControl('order_now_button').click() was all I need. It works great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2019 10:35 AM
you can use getXMLWait.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2020 09:00 AM
not on the portal though
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2021 07:18 PM
I couldn't get g_form.OrderNow() to work on Service Portal and g_form.getControl('order_now_button').click() doesn't work either.
This article will shows how to use g_form.getActionName() and g_form.submit('name_of_action') to get it working as of the Rome release:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0779964