Return false; not working in on submit client script

Dotychczas
Mega Guru

Hello Experts,

I created following client script:

function onSubmit() {
	//Type appropriate comment here, and begin script below
	var ga = new GlideAjax('AuditsAjaxInclude');
	ga.addParam('sysparm_name', 'checkDates');
	ga.addParam('sysparm_remark_nr', g_form.getUniqueValue());
	ga.getXML(checkRemarks);

	function checkRemarks(response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		alert(answer);
		if(answer == 'false'){
			alert('Estimated or Updated date are before Due date.');
			return false;
		}
	}
}


script works as expected but user is still able to submit the form even with return false. What is the issue here? 

Thanks in advance!

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi @Dotychczas 

the already proposed method getXMLWait() is NOT recommended and also doesn't work in Service Portals.

For your case, you need a special pattern. See the following article for the approach: https://community.servicenow.com/community?id=community_blog&sys_id=dc49feeadbdd7f0c54250b55ca96191d...

Kind regards
Maik

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

If you change this to getXMLWait then it will work.

Onsubmit script with getXML has conflicts.

 

Alternatively you can try a before insert or before update br that runs and checks this and aborts the action if needed.

-Anurag

 

-Anurag

Maik Skoddow
Tera Patron
Tera Patron

Hi @Dotychczas 

the already proposed method getXMLWait() is NOT recommended and also doesn't work in Service Portals.

For your case, you need a special pattern. See the following article for the approach: https://community.servicenow.com/community?id=community_blog&sys_id=dc49feeadbdd7f0c54250b55ca96191d...

Kind regards
Maik

Hi @Dotychczas 

In case you think I was able to answer your question, I would be happy if you mark the appropriate response as "correct" so that the question will appear as resolved for other users who may have a similar question in the future.

If not, please tell me what you are still missing!

Many thanks & kind regards
Maik

LAXMI TODAKAR2
Tera Contributor

Hi,

Below solution is worked for me, please find the link below.

https://www.servicenow.com/community/developer-forum/using-return-false-in-glide-ajax/m-p/1567135