- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2025 04:26 AM
but this is populating the error message but not aborting the action.
I have tried return false but no use.
how to solve this?
function onSubmit() {
// Retrieve the variable values
var requestedFor = g_form.getValue('requestor'); // Replace with the actual variable name
var spaceName = g_form.getValue('u_ref_name_of_qlik_sense_space'); // Replace with the actual variable name
var accessType = g_form.getValue('u_sb_access_level_required'); // Replace with the actual variable name
var isValid = false;
// Call the Script Include to check for duplicates
var ga = new GlideAjax('RITMValidation');
ga.addParam('sysparm_name', 'checkDuplicateRITM');
ga.addParam('sysparm_requested_for', requestedFor);
ga.addParam('sysparm_space_name', spaceName);
ga.addParam('sysparm_access_type', accessType);
ga.getXMLAnswer(function(response) {
//var answer = response.responseXML.documentElement.getAttribute('answer');
var answer = response;
if (answer === 'duplicate') {
g_form.addErrorMessage('A request with the same details already exists.');
// return false; // Prevent form submission
//g_form.submit(false);
} else {
isValid = true;
}
return isValid;
});
}
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2025 06:28 AM
So are you saying it's working as expected?
if not then check how to handle onSubmit with GlideAjax and perform the validation which will work in both native + portal
Refer these links for workaround/solution on how to use Synchronous GlideAjax in onSubmit
How To: Async GlideAjax in an onSubmit script
Asynchronous onSubmit Catalog/Client Scripts in ServiceNow
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2025 04:33 AM
this is for catalog form?
If yes then the async GlideAjax won't work in native or portal as the form will get submitted by the time the script include function performs the validation
please share some more details
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2025 05:06 AM - edited ‎01-21-2025 05:08 AM
yes this is for catalog item request.
so when a user tries to submit a request by filling some fields, my requirement is to validate those fields with already submitted RITM variable values and display error message mentioning a request has already been submitted for these details.
So I am using a script include and on submit client script for this, On Submit CS fetches the values of the new request and sends to SC for validation and SC returns whether it is duplicate or not. Then CS pops up an error message and aborts the submission. I have tried the following CS as well
function onSubmit() {
// Retrieve the variable values
var requestedFor = g_form.getValue('requestor'); // Replace with the actual variable name
var spaceName = g_form.getValue('u_ref_name_of_qlik_sense_space'); // Replace with the actual variable name
var accessType = g_form.getValue('u_sb_access_level_required'); // Replace with the actual variable name
// Call the Script Include to check for duplicates
var ga = new GlideAjax('RITMValidation');
ga.addParam('sysparm_name', 'checkDuplicateRITM');
ga.addParam('sysparm_requested_for', requestedFor);
ga.addParam('sysparm_space_name', spaceName);
ga.addParam('sysparm_access_type', accessType);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer === 'duplicate') {
g_form.addErrorMessage('A request with the same details already exists.');
return false; // Prevent form submission
} else {
return true;
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2025 06:28 AM
So are you saying it's working as expected?
if not then check how to handle onSubmit with GlideAjax and perform the validation which will work in both native + portal
Refer these links for workaround/solution on how to use Synchronous GlideAjax in onSubmit
How To: Async GlideAjax in an onSubmit script
Asynchronous onSubmit Catalog/Client Scripts in ServiceNow
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2025 06:49 AM
no Ankur, just the error message is populating but not aborting the submission.