How to do it...

  1. Open your AL project folder in Visual Studio Code.
  2. 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;}
  1. 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(); ...

Get Microsoft Dynamics 365 Business Central Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.