Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

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


Level 10

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";"Header.FocusField");


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.



Level 10
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 😞


The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now