
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 04:01 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 12:12 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 10:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2018 06:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2018 05:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 12:12 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 12:43 PM
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