Validating data
It is important to make sure that the data being placed into the fields is correct. Many of the checks done to the data can be performed using the field's properties, but in some instances you will need to write code to do very specific data validation. Here we will show you where that code should go and what can be done there.
Getting ready
You will need the customer card from the Creating transactions to alter data recipe.
How to do it...
Create a new codeunit from Object Designer.
Add the following global variable:
Name
Type
Subtype
Customer
Record
Customer
Add the following code to the
OnRun
trigger:Customer.SETCURRENTKEY(Name); Customer.SETRANGE(Name, 'Alex Traxinger'); IF Customer.FINDFIRST THEN BEGIN Customer."Search Name" := ''; Customer.VALIDATE(Name, 'Matt Traxinger'); Customer.MODIFY; END;
Save and close the codeunit.
How it works...
Most of the code in our example is to find and save a record. We're going to look at the following lines:
Customer."Search Name...