
- 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 04:24 AM
Hi, it seems this is wrong here
ga.getXMLAnswer(checkemailResponse);
check this one.
Example code:
var ga = new GlideAjax('HelloWorld'); //Here HelloWorld is the script include name
ga.addParam('sysparm_name','helloWorld'); // we are calling helloWorld function
ga.addParam('sysparm_user_name',"Bob"); //we are passing paramter Bob
ga.getXML(HelloWorldParse); or // ga.getXMLWait();
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 04:33 AM
Hi,
Replace "sysparm_a1" with "sysparm_name".
Thanks,
Prateek

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 04:58 AM
Hi Kopal Garg,
To pass variable value as query parameter, don't need to use quotes:
Your code
gr.addQuery('email','email_ajax');
Should be replaced with
gr.addQuery('email',email_ajax);
To call Script using AJAX, you need:
1. Create GlideAjax object:
var ga = new GlideAjax('your_script_name');
2. Specify options for calling a function from ершы script:
ga.addParam('sysparm_name', 'function_name'); // function name to call
// [Optional] if function has parameters
ga.addParam('sysparm_parameter_name', "Bob");
3. Use callback function to call the script function:
ga.getXML(someFunction);
function someFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// place your code here
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2018 08:01 AM