Creating transactions to alter data
The purpose of NAV is to help you use business data to improve the way your company operates; that data needs to be saved in the database. This recipe will show you how to add, change, and remove data or records from the tables in the NAV system.
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 of your codeunit:Customer.Name := 'Matt Traxinger'; Customer.INSERT(TRUE); Customer.SETCURRENTKEY(Name); Customer.SETRANGE(Name, 'Matt Traxinger'); IF Customer.FINDFIRST THEN BEGIN Customer.Name := 'Alex Traxinger'; Customer.MODIFY; END;
Save and close your codeunit.
How it works...
First we fill out the field in our customer record. In this case, it's the Name field and we set it to the value Matt Traxinger. The next line actually inserts the value into the database.
The first three lines of the next section retrieve the data...