Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Returning true / false when using scripts in the validate event


Level 4
Hi all,

I'm using a script in teh validate event to determine a false or true response and then when all the checking has been done I use:

if (matchFound) {

return true;


However this is coming up with the error message:

Error: Illegal 'return' outside of a function body, Line:21

Now obviously this means my return is in the wrong place, but where should it go? How can you pass on that a validate script, inside the event, has failed when using execValidate?

Many thanks,

4 Replies


Former Community Member

execValidate() does not have a return value. Should "if (matchFound) { return true; }" exist within a validate event you will not get a boolean response.


To do the type of validation you are hinting at requires an alternative approach. You could consider using script objects.



Level 4

By wrapping the execute in an if statement you can tell if it managed to execute correctly or failed.

if (this.parent.parent.execValidate()) {

this.parent.parent.presence = "hidden";

Question2.presence = "visible";



Will only move on to the next question if the form addressed(this.parent.parent) has validated correctly.

The problem I am having is that I wanted to use the validate event to check if a field contained a valid entry.


This quite clearly says that you can return a false or true:

"Calculations and scripts on the validate event are required to return true or false (expressed in a format appropriate to the scripting language) corresponding to a validation that succeeds or fails, and must not affect the overall form structure of form values."

But when I try to return a true or false it tells me I can't.

As I have a deadline to get this done I will be forced to run this in a scripting object, but I don't understand the reason for having a validate event at all if you cannot tell if that validate event succeeded.



Former Community Member
Do not use the keyword return...simply use true or false.

Like this:

if (this.rawValue == "Paul"){


} else {




Level 4
Thank you Paul!

Legend as always. Not going to go back through my form though, deadline is up and I've had to fix it with scripting objects :(