"return false;" not working onSubmit in Service Portal

patricklatella
Mega Sage

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
}
}
}

 

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

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.

View solution in original post

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

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.

Hi Sanjiv,

I ended up doing just that...I created an onChange catalog client script on one of the other mandatory fields and then present the popup again then and as well clear the value of the mandatory field so it's impossible to submit the form when the Class is "User".  thanks as always for your help!