- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 09:32 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 09:52 PM
Let's give my adjustment below for your given script.
function onSubmit() {
//Add below lines to your script
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName();
// Get the Clarity ID from the form
var clarity_id = g_form.getValue('id');
// Create a new GlideAjax instance
var ga = new GlideAjax('Cvks');
ga.addParam('sysparm_name', 'validateValue');
ga.addParam('sysparm_value', id);
// Call getXML with the callback function
var clar = ga.getXML(value);
//Add this to your script
return false;
// Callback function to handle the response
function value(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == "IncorrectID") {
g_form.addErrorMessage("incorrect");
//Add this line to your script.
return false;
} else if (answer == "CorrectID") {
g_form.addErrorMessage('correct');
//Add below lines to your script.
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 09:46 PM
Hi @Pavan rishi
Let's have a look to the below article on how to do async validation in an OnSubmit client script.
The GlideAjax (Asynchronous) does not work on onSubmit Client Script. This is because of the fundamental behavior of Asynchronous scripts which are non-blocking by nature.
KB0783579 - How to do async validation in an onsubmit client script.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 09:52 PM
Let's give my adjustment below for your given script.
function onSubmit() {
//Add below lines to your script
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName();
// Get the Clarity ID from the form
var clarity_id = g_form.getValue('id');
// Create a new GlideAjax instance
var ga = new GlideAjax('Cvks');
ga.addParam('sysparm_name', 'validateValue');
ga.addParam('sysparm_value', id);
// Call getXML with the callback function
var clar = ga.getXML(value);
//Add this to your script
return false;
// Callback function to handle the response
function value(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == "IncorrectID") {
g_form.addErrorMessage("incorrect");
//Add this line to your script.
return false;
} else if (answer == "CorrectID") {
g_form.addErrorMessage('correct');
//Add below lines to your script.
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
}
}
Cheers,
Tai Vu