Returning a Boolean Result

Several different contexts in ADF runtime expect your groovy script to return a boolean true or false result. These include:

  • custom field's conditionally updateable expressions

  • custom field's conditionally required expressions

  • object-level validation rules

  • field-level validation rules

  • conditions for executing an object workflow

Groovy makes this easy. One approach is to use the groovy true and false keywords to indicate your return as in the following example:

// Return true if value of the Commission custom field is greater than 1000
if (Commission_c > 1000) { 
  return true
}
else {
  return false
}

However, since the expression Commission_c > 1000 being tested above in the if statement is itself a boolean-valued expression, you can write the above logic in a more concise way by simply returning the expression itself like this:

return Commission_c > 1000 

Furthermore, since Groovy will implicitly change the last statement in your code to be a return, you could even remove the return keyword and just say:

Commission_c > 1000

This is especially convenient for simple comparisons that are the only statement in a validation rule, conditionally updateable expression, conditionally required expression, formula expression, or the condition to execute an object workflow.