I am trying to setup a field verification on the Project Form that will validate the CustID_c (Project_UD) field to make sure that it is a Valid Customer.CustID.
What is the best way to do this?
I have tried to use Leave and Before/AfterFieldChange. But the problem is that if I am purposely typing an incorrect ID in multiple times then it will just send the error message multiple times in one.
I want the ability to push the Search Button for the Customer and I have that working, but I also want the ability to type in a CustID, but want it to validate that it is a correct Customer.CustID or it will give an exception. I can get the message to pop up, but it still does some interruption for the entire form process.
I try to do data validation in BPMs. That will protect data coming from a screen or DMT or even REST. Screen customizations are good for lookups, etc. but the BPM is my gate keeper for data. Just my humble opinion.
You can (and should - it’s the reason it exists) use the .Validating event on the textbox. It’s not listed in the wizards but nothing stops you from binding to it:
// In Form.Load or InitializeCustomCode():
txtProjectCustId.Validating += txtProjectCustID_Validating;
// In DestroyCustomCode():
txtProjectCustId.Validating -= txtProjectCustID_Validating;
// In your script:
private void txtProjectCustID_Validating(object sender, CancelEventArgs e)
{
// Validate your CustID here and if it fails:
e.Cancel = true;
}
The problem with working with a BPM is that there is not a business object set to immediately catch a UD field on a table. We want to inform the user immediately upon data entry rather than waiting until a Save or something. So this won’t work either for a UD column.
We had the same. For us, the Order held the Customer that we we’re selling to but the Contract Customer was the “End User” or where we were ultimately installing.
This is where @Louis_Fequet suggestion of using the validate event to check the field value would come into play. Also, using a search instead of allowing freeform entry prevents errors in the first place. Just something to think about.
But a search involves clicks, and there’s nothing a data entry person hates more than having to use that pesky mouse, when a few tabs would be so much faster…
The code I posted above will work fine to validate a text box immediately.