I have a datawindow containing multiple fields. I want to write a validation expression for a field named amount
. I have another two fields named debit
and credit
. If the sum of debit and credit is greater than amount, then I want to show a validation message to the user.
How can I write the required validation expression in the Column Specification of that datawindow?
I also want to write validation expression for a field named test
. There is a field named criteria
. When this field is set to 1, I want the test field to be a required field. How can I write validation expression for this?
There are different ways to do this, depending on whether you have to use the column's required validation expression or have the license to do it different ways.
Design Considerations
Is this going to be a freestyle datawindow where you only need to validate the rule once for the screen, or a tabular style where users can mass enter sets of data and the rule needs to be applied to each row?
Do you want to require the users to enter the correct values each time a required field gets focus or do you want to let them freely navigate the screen and validate at save time?
You'll get some different responses here, I expect, but I prefer to use the column specification expressions only for simple checks because:
However, I'll grant that dw expressions are generally really fast.
Using a Computed Field for Validation Rules
One alternative technique is also a fast performer and can be used in most versions of PB.
cf_amount_rule
and something like this in the expression: if (debit + credit = amount, 0, 1)
cf_amount_rule
and you now have a handy reference point that quickly tells you when there is an errorOO purists might suggest that it's wrong to put logic in the datawindow and if you find yourself putting in the same rule in multiple datawindows that's certainly a code smell. But for simple rules that are unlikely to change I have found time and again that the datawindow is very efficient at running these rules and saving you from having to write lots of code elsewhere.
Optional Goodies
cf_amount_rule
.