- 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 06:58 AM
that's what I mentioned the form will get submitted and won't wait for the script include function
check the links which I shared above
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:56 PM
Hope you are doing good.
Did my reply answer your question?
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-22-2025 02:43 AM
Hi Ankur, yes it worked. Thanks for the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 05:44 AM
Hi @Rahul Raja Sami ,
you are returning nothing from onSubmit function. You only returning value from XMLAnswer but onSubmit function it self is returning nothing.
Please see updated script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 02:37 AM
this is not working just displaying the error message but not aborting the submission.