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

Geoff_T
Mega Sage

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

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

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

Akshat
Tera Contributor

The script is working but affecting other request types also.