Issue in client callable Catalog client script

Kopal Garg
Tera Expert

Hello All,

 

I am new to GlideAjax and trying to check duplicate email address on a catalog form. I am getting "Failed to load resource: the server responded with a status of 404 (Not Found)" on submitting the form because of the script include and catalog script running in the background. Can anyone help what mistake I am making here?

-----------------------------Script include: "Name: EmailIDDuplicate" ---------------------------------

var EmailIDDuplicate = Class.create();
EmailIDDuplicate.prototype = Object.extendsObject(AbstractAjaxProcessor,{
duplicatecheck : function()
{
var email_ajax = this.getParameter('sysparm_a2');
var gr = new GlideRecord('sys_user');
gr.addQuery('email','email_ajax');
gr.query();
try
{
if(gr.next())
{
alert("Alert box of script");
return true;
}

else{
return false;
}
}
catch(err)
{
gs.log("Error is : "+err);
}
},
type: "EmailIDDuplicate"
});

 

---------------------------- Catalog client Script------------------------------

function onSubmit() {
//Type appropriate comment here, and begin script below

var email_value = g_form.getValue('email');

var ga = new GlideAjax('Email ID duplicate check');
ga.addParam('sysparm_a1', 'duplicatecheck');
ga.addParam('sysparm_a2', 'email_value');
ga.getXMLAnswer(checkemailResponse);

function checkemailResponse()
{
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true')
{
g_form.showErrorBox("Duplicate email");
g_form.setValue('email','');
}
else
{
return true;
}
}
}

 

Regards,

Kopal

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

Do you need the solution to support the Service Portal?  If not, then you can do it right in the onSubmit() Client Script:

function onSubmit() {
	var emailAddress = g_form.getValue("email");
	var gr = new GlideRecord("sys_user");
	gr.addQuery("email", emailAddress);
	gr.query();
	if (gr.next()) {
		g_form.showFieldMsg("email","Found an existing User record with the same email address", "error");
		return false;  //abort the submit
	} else {
		return true;  //carry on
	}
}

GlideAjax and onSubmit scripts do not really go together, as the result from the Script Include would normally arrive back at the client after the submission was completed and moved on from the form so the answer could not even be evaluated.

Because the check is happening on submission, the user is no longer interacting with the form, so there is no need to use an Ajax call.  They are just waiting on the submit to finish.

View solution in original post

12 REPLIES 12

Hi Somveer,

 

Thank you for your response. I checked all mentioned points but still getting the same error.

------Client Script------// UI type is "All"

 

function onSubmit() {
//Type appropriate comment here, and begin script below

var email_value = g_form.getValue('email');

var ga = new GlideAjax('EmailIDDuplicate');
ga.addParam('sysparm_name',"duplicatecheck");
ga.addParam('sysparm_email',"email_value");
ga.getXML(checkemailResponse);

function checkemailResponse(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true')
{
g_form.showErrorBox("Duplicate email");
g_form.setValue('email','');
}
else
{
return true;
}
}

}

 

------- Script Include-------

 

var EmailIDDuplicate = Class.create();
EmailIDDuplicate.prototype = Object.extendsObject(AbstractAjaxProcessor,{
duplicatecheck : function()
{
var email_ajax = this.getParameter('sysparm_email');
var gr = new GlideRecord('sys_user');
gr.addQuery('email',email_ajax);
gr.query();
try
{
if(gr.hasnext())
{
alert("Alert box of script");
return true;
}

else{

return false;
}

}
catch(err)
{
gs.log("Error is : "+err);
}
},

//type: "EmailIDDuplicate"


});

 

Kindly post your suggestion.

 

Regards,

Kopal

1. Un-comment the Type at bottom of script include: type: "EmailIDDuplicate" 2. Remove the quotes in client script when passing the email parameter: ga.addParam('sysparm_email',email_value);

Hi,

This is correct. the script include must have that 'type' statement. Thus it is giving the 404 response error code. Also in the Script include, remove alert statement. You can use gs.addInfoMessage() for that purpose.

 

Regards,

Manan Raval

Jim Coyne
Kilo Patron

Do you need the solution to support the Service Portal?  If not, then you can do it right in the onSubmit() Client Script:

function onSubmit() {
	var emailAddress = g_form.getValue("email");
	var gr = new GlideRecord("sys_user");
	gr.addQuery("email", emailAddress);
	gr.query();
	if (gr.next()) {
		g_form.showFieldMsg("email","Found an existing User record with the same email address", "error");
		return false;  //abort the submit
	} else {
		return true;  //carry on
	}
}

GlideAjax and onSubmit scripts do not really go together, as the result from the Script Include would normally arrive back at the client after the submission was completed and moved on from the form so the answer could not even be evaluated.

Because the check is happening on submission, the user is no longer interacting with the form, so there is no need to use an Ajax call.  They are just waiting on the submit to finish.

Hi Jim,

Thank you for your response. I am looking forward for a check on duplicate email address on service portal. Normal onSubmit() script was working fine in IS view. But none of my script is running fine on service portal. Tried with "UI type" type check, try-catch error handling.

Regards,

Kopal