API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Validation Formula Pet Peeve
Being consultants, we get to see a lot of Notes applications that others have developed. One thing in particular that we see very often has to deal with Input Validation formulas, in combination with forms that refresh fields on keyword change.

The most obvious use for Input Validation formulas is to verify that a field has been filled out. As an example, let's say you have a field called email and you want to make sure it has been filled out. You could use an input validation formula like this:

@If(Email = ""; @Failure("Please enter in your email address."); @Success)

This seems pretty straightforward. Now, let's say you have a keyword field somewhere on your form. And you have some hide-when formulas based on this keyword field (if option #1 is selected, these fields appear, but if option #2 is selected, these other fields appear). So, to implement this, you set the field property "Refresh fields on keyword change". Now, if the email field is blank when the keyword field has its value change, you'll get a message "Please enter in your email address."

Some people may not mind that extra message when changing a value that has nothing to do with the email address, but it's a pretty simple thing to eliminate. The field really only needs to be required when the document is being saved. When the document is being refreshed ("recalculated" in formula language terms) then it shouldn't be required. So changing the validation formula to this will eliminate the message:

@If(@IsDocBeingRecalculated; @Success; Email = ""; @Failure("Please enter in your email address."); @Success)