Does anyone have any suggestions on how to add extra validation to a standard GP field while doing the following?
- Force the user to reenter the value.
- Not clear the value that failed validation (the user can edit another table to fix the problem)
- Allow standard validation to reexecute even if the entered value does not change.
I'd rather not clear the new value and make the user reenter it. If I did that I'd also need to add a field to store the old value to revert the entry or just clear it. If there is no other method that works well then I might just have to do this anyway.
I've found it's easy enough to add extra validation to any field, in this specific case I'm using the first segment of the customer's sales and COG accounts and the 2nd and 3rd segment from an item for the GL distribution for invoice lines. When the item number on the sop entry form is validated I need to make sure the appropriate GL code exists. If it doesn't, a message is displayed and validation should fail.
ValidateBeforeOriginal(
object sender, System.ComponentModel.CancelEventArgs e)
This lets you set e.cancel to true but that just stops the standard GP from proceeding. It doesn't stop the navigation to the next field so the LeaveBeforeOriginal and LeaveAfterOriginal will still fire even if you add a focus() command to put the focus back to the field you validated.
The main problem here is that even if you use ForceValidate(true) in either the before or after validation event only your custom validation event fires. Unless the field's value changes the standard GP validation isn't forced by ForceValidate(true). On the order/invoice lines the user is also prompted if they want to replace the item number if ForceValidate(true) is used in the ValidateAfterOriginal event. Even after that the standard validation doesn't work corretly afterwards, i.e. the uom, price, etc. aren't populated.
I can add my validation in the LeaveBeforeOriginal event but that has other problems such as validating when the field hasn't changed. The Leave events fire before the Close events unfortunately so I can't set a flag and avoid firing the Leave events, twice, before the form closes.
*This post is locked for comments