- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 05:18 PM
Hi all,
I've got an onSubmit catalog client script to present a modal to redirect the user from our CSM portal to our old CMS portal. The logic determines if the user has Class = "sys_user" or Class = "customer_contact". If the user's Class is "sys_user" I want to show the popup and then block the form from being submitted. I've got the popup showing but the "return false;" is not working. Thanks!
Here's my client script:
function onSubmit() {
//if logged in user is not a Contact, direct them to the ESS portal
var user = g_form.getValue('logged_in_user');
var ga = new GlideAjax('CSMContactClassLookup');
ga.addParam('sysparm_name','getClass');
ga.addParam('sysparm_user', user);
ga.getXML(getClassResponse);
function getClassResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('answer is '+answer);
if(answer == 'sys_user'){
spModal.open({
title: 'Got an issue?',
message: 'To report an issue you need to use a different form in our ESS portal. <p><p>Click the button below to redirect to the correct form.',
buttons: [
{label:'Take me to the correct form', primary: true},
{label:'Stay on this page', cancel: true}
]
}).then(function(){
location.href="ess/main_content.do?sysparm_content_url=com.glideapp.servicecatalog_cat_item_view.do%3fsysparm_id%3d3f1dd0320a0a0b99000a53f7604a2ef9";
});
return false;//this is not working, the form still submits
}
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 08:56 PM
You should change this to an onChange client script. GlideAjax with getXML wont work in onSubmit client script, since it is asynchronous. And getXMLWait() wont work on Service Portal. So I would suggest adding it on onChange and clear the value 'logged_in_user'
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 05:33 PM
Hi patricklatella,
Can you confirm your UI type selected as All ?
Also check your browser console in chrome any error your are seeing ?
Also you are allowing user to fill form and then running your validation might be frustrating for user to full form and then be presented with info that its a wrong form 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 08:52 PM
Hi Ankush, thanks for the response. This is a unique use case where actually onLoad I present the user (if their Class is User) with the popup that redirects them to our CMS portal. This is to prevent them from ignoring that popup and trying to submit the form anyway. I agree that preventing them continuing with the form at all if it's the wrong form would be a better UX.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 06:35 PM
GlideAjax makes an Asynchronous call to the server.
You need to use getXMLWait() for an onSubmit to make it synchronous.
Otherwise, it will just submit immediately.
ga.getXMLWait(getClassResponse);
If you are working out of application scope, getXMLWait isn't available and you will need to re-engineer your whole solution to not use GlideAjax.
You could do this by doing your GlideAjax on load and setting a scratchpad variable, then checking that variable onSubmit.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2019 09:03 PM
thanks for the response Paul, yeah I think the issue is that this record producer is in the Customer Service application scope, so I'm thinking getXMLWait won't work. I'll try another approach.