How to show error message through OnSubmit client script? & Not show Order Confirmation Pop-up? and stop the request from Submitting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2021 12:57 AM
Hi,
I have a Catalog Item in which I have a On Submit Script which needs to show Error Message when the request is Submitted with Duplicate Variables.
But As soon as I submit the Error Message is shown but the Order Confirmation Pop-up shows up and the request can still be Check Out.
Which is eventually leading for the request to be submitted.
Same issue I am facing when I click on Add to Cart it shows the Error Message but the request eventually gets Submitted and the item is added to Cart.
Could you please provide a method where I can Show the error message and stop the request from Submitting -
- The Order Confirmation Pop up window should not show up.
- The Item should not be added to the Cart.
And only the Error Message should show up and the request is stopped from Submitting.
PFA Screenshots of the issue.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2021 01:17 AM
Hello,
You need to return false if you are not already doing so, like this example:
function onSubmit()
{
var variableName = g_form.getValue("VariableName");
if(variableName == "")
{
alert("Show Pop Up Message");
// stop submission
return false;
}
}
Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2021 01:57 AM
Hi Geoff,
I have added return false;
Still the request is not stopping from Submitting.The Error screenshots are attached to the question.
Below is the code.
function onSubmit()
{
var sn = g_form.getValue('sla_name');
var gd = new GlideAjax('DuplicateCheck');
gd.addParam('sysparm_name', 'checkDuplicate');
gd.addParam('sysparm_sysidvar1', sn);
gd.getXMLAnswer(function(answer)
{
if(answer=='Duplicate')
{
g_form.clearValue('sla_name');
g_form.addErrorMessage("This is a Duplicate Value");
return false;
}
});
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2021 02:08 AM
Ah, it is a GlideAjax call, that explains why it is not working. I would suggest reading this article to understand why you are not getting the result you expect. There is also an alternative solution proposed:
https://snprotips.com/blog/2018/10/19/synchronous-lite-onsubmit-catalogclient-scripts
I hope this helps you towards a solution.
Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2024 06:43 AM
The script is working but affecting other request types also.