How to show error message through OnSubmit client script? & Not show Order Confirmation Pop-up? and stop the request from Submitting.

Kunal Sharma1
Kilo Explorer

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 -

  1. The Order Confirmation Pop up window should not show up.
  2. 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

7 REPLIES 7

Ashish Arovind1
Giga Expert

Hi Kunal

 

If you are only returning an error message then it will not stop from submitting the request . 

 

you can add ' return false; ' in the if loop of your script to restrict the user from submitting the request .


Regards
Ashish Raj

Hi Ashish

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

Community Alums
Not applicable
You are using async here and it will not wait.here retrun false will not work.try to use getxml wait here .so whenever you will use asynchronous call your code will work but make sure this code will not work on service portal