- Open your AL project folder in Visual Studio Code.
- In the Visual Studio Code Explorer, select the Television Show.al file. In the Editor tab, add two new fields named Last Aired and Created By, as follows:
field(6; "Last Aired"; Date){}field(7; "Created By"; Code[50]){ Editable = false;}
- When a new record is added to the Television Show table, we want to know who created it. We can do that by adding code to the OnInsert() trigger of the table so that our logic executes every time a record is inserted.
In the Television Show.al file, add the trigger and logic after the keys section. All we need to do is set the Created By field to the ID of the current user, as follows:
trigger OnInsert()begin "Created By" := UserId(); ...