Exercise - Create a table
Simon is a developer working for CRONUS International Ltd., which has decided to start selling Microsoft Dynamics 365 Business Central training courses as its business.
Simon needs to create a table to record course information and set several keys so that users have the option for a different sorting sequence for the records in the table.
Tasks
Create a new table with snippets.
Set basic field properties.
Create primary and secondary keys for the table.
Learn to work with FlowFields.
Steps
Start Visual Studio Code.
Select View and then Extensions (Ctrl+Shift+X).
Enter AL Language in the Search Extensions in the Marketplace search box.
Select the green Install button.
Create a new AL extension project. Select View > Command Palette... (Ctrl+Shift+P).
Enter AL: Go! in the search box and select the command from the list.
Accept the suggested path (or enter another path).
Select the 4.0 Business Central 2019 release wave 2 target platform.
Select Microsoft cloud sandbox as the development endpoint.
Download the application symbols. Select View > Command Palette... (Ctrl+Shift+P).
Enter AL: Download symbols in the search box and select the command from the list.
If requested, provide your organizational credentials (Microsoft 365 account/Microsoft Entra ID account).
Open the app.json file. Change the name setting to Course Mgmt and change the publisher setting to Cronus International Ltd.
Remove the HelloWorld.al file.
Select File > New File and immediately save this file by selecting File > Save. Give this file the name Course.Table.al.
Create a new table in this file by using code snippets. Enter ttable and press the Tab key.
Change the ID to 50100 and the name to CRONUS Course.
Set the DataClassification property to CustomerContent and set the Caption property to Course.
Remove the field MyField.
Create the following fields. You can use the tfield snippet.
Field No. | Field name | Data type | Length |
---|---|---|---|
10 | Code | Code | 10 |
20 | Name | Text | 30 |
30 | Description | Text | 50 |
40 | Type | Option | |
50 | Duration | Decimal | |
60 | Price | Decimal | |
70 | Active | Boolean | |
80 | Difficulty | Integer | |
90 | Passing Rate | Integer | |
100 | Instructor Code | Code | 20 |
Set the DataClassification property for each field in the table to CustomerContent.
Set the Caption property for each field in the table.
Set the OptionMembers property for the Type field to Instructor Led, e-Learning, Remote Training. Also set the OptionCaption property.
Set the TableRelation property for the Instructor Code field to the Resource table and only show the resources where the type is Person. You can use Resource where(Type = const(Person)).
Set the Primary Key field to Code. Use the name PK for this key.
Add secondary keys for Instructor Code and for Type. Give them the name Key1 and Key2.
Remove the other code in the file. Remove the variable myInt and all the trigger codes (OnInsert, OnModify, and so on).
Open the launch.json file in the .vscode folder, and then set the startupObjectId setting to 50100 and the startupObjectType to Table.
Publish your extension to the sandbox. Select View > Command Palette... (Ctrl+Shift+P).
Type AL: Publish (F5) in the search box and select the command from the list.
Verify that the Business Central application launches and a page appears with the columns that you defined on your table. At this moment, you are not able to enter data.
Create another field in the table with the name Instructor Name.
Field No. | Field name | Data type | Length |
---|---|---|---|
120 | Instructor Name | Text | 50 |
Set the Editable property to false, the FieldClass property to FlowField, and the CalcFormula property to "lookup(Resource.Name where("No." = field("Instructor Code"))).
Save your file.