return false not working in glideajax in onsubmit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 08:36 AM
could pls let me know what is wrong in below client script, how this can be updated further form is not submitting after validation is set to true ... in the below script i have also used a hidden checkbox variable if condition satisfied i am setting validation as false in the else case it is setting ture based on this check i am trying to submit the form but still that is not submitting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 09:28 AM - edited 08-07-2024 09:30 AM
I haven't run the code, but the return false on line 5 is preventing the form submission. Try this approach instead:
var ga = new GlideAjax('CheckUserStatus');
ga.addParam('sysparm_name', 'checkStatus');
ga.addParam('sys_id', userIDsToCheck.join(','));
ga.getXML(CheckValidation);
function CheckValidation(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
answer = answer.toString().split(';');
if (answer[1] > 0) {
alert('inactive user count: ' + answer[1]);
alert('Inactive User IDs: ' + answer[0]);
g_form.clearValue('dl_creation_group_members');
g_form.addErrorMessage('Some user IDs are inactive. Please correct the input.');
return false;
}
}
Assuming you are running this in an onSubmit client script, you don't need to do anything to submit the form if the validation check passes, as this is already built into the function of this client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2024 11:38 AM
function onSubmit() {
var userIDsToCheck = []; // Populate this array with actual user IDs
var ga = new GlideAjax('CheckUserStatus');
ga.addParam('sysparm_name', 'checkStatus');
ga.addParam('sys_id', userIDsToCheck.join(','));
ga.getXMLAnswer(function(response) {
var answer = response.split(';');
if (answer[1] > 0) {
alert('Inactive user count: ' + answer[1]);
alert('Inactive User IDs: ' + answer[0]);
g_form.clearValue('dl_creation_group_members');
g_form.addErrorMessage('Some user IDs are inactive. Please correct the input.');
// Set checkbox to false
g_form.setValue('validation', 'false');
// Prevent form submission
g_form.setAbortAction(true);
} else {
// Set checkbox to true
g_form.setValue('validation', 'true');
// Allow form submission
g_form.setAbortAction(false);
}
});
// Return false to prevent the form from submitting immediately
return false;
}
If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!