Customizing Microsoft Dynamics Business Central on premises using AL Code Functions

Customizing Microsoft Dynamics Business Central on premises using AL Code Functions

If you’re new to Microsoft Dynamics Business Central on premises, you need to know how to easily customize it. In this blog, you’ll learn how to do customizations using AL code functions, including use of Message statements, how to insert a record, and how to modify a record, which makes it easy and fast. This example discusses how to display the information and insert and modify a record in the Customer table using AL Code.

Step 1: Message Statement

There are multiple predefined statements in AL Code. One such predefined statement is “Message.” This is used to display information.

Create a new file for the codeunit. Be sure to use a standard file name format for files. To create the codeunit, use the shortcut or Snippet (tc). You will be presented with many options; select tcodeunit.

Figure 1 – Creating a new file for a codeunit and by using snippet in Dynamics Business Central on premises
Figure 1 – Creating a new file for a codeunit and by using snippet in Dynamics Business Central on premises

A variable can be defined with a global or a local scope. If you define your variable with a global scope, it will be available everywhere in the object. So, on every trigger, everywhere you want to write code statements, that variable will be available.

When the scope is local, you can only access that variable in the specific trigger where it was declared. The example below uses global variables just for additional details. It uses three variables, but the mytext variable is enough for this message statement.

Figure 2 – Declaring variables and assigning those values to message statements / Functions in Dynamics Business Central on premises
Figure 2 – Declaring variables and assigning those values to message statements / Functions in Dynamics Business Central on premises

Create a new file for the page extension. Again, be sure to use a standard file name format for files. For creating the page extension, use the shortcut or Snippet (tpage). You are presented with several options; select tpageext.

Figure 3 – Creating a Page extension and by using snippet (As shown below) in Dynamics Business Central on premises
Figure 3 – Creating a Page extension and by using snippet (as shown below) in Dynamics Business Central on premises

This page extension tells where you want to extend the actions or features. In this screenshot, you see how to extend the features in the customer list, or you can use 22 instead of “customer list” because 22 is the page number of customer list.

Figure 4 – Creating a page extension (assigning the variable to codeunit and codeunit name) in Dynamics Business Central on premises
Figure 4 – Creating a page extension (assigning the variable to codeunit and codeunit name) in Dynamics Business Central on premises

Use F5 in keyboard or the shortcut Ctrl + G to select > AL: Publish. You will now see the output of the Message Statement.

Figure 5 –This is the output of message statement in Dynamics Business Central on premises
Figure 5 –This is the output of message statement in Dynamics Business Central on premises

Step 2: Insert a Record in Customer Table

Create a new file for inserting a record. For creating the codeunit, use the shortcut or Snippet (tc).

In this example, a record is inserted using the INSERT function. INIT refers it to set default values to the table. Some fields are added here, and the variables syntax shows that the values are taken from the record, with customer as the table name.

Figure 6 – Creating a new file for codeunit to insert a record in Dynamics Business Central on premises
Figure 6 – Creating a new file for codeunit to insert a record in Dynamics Business Central on premises

Create a page Extension for inserting a record in the customer table. Use the shortcut or Snippet (tpage).

Here, you again clearly state where you want to add this action as well as the action name. Again, you can use 22 instead of “customer list” because 22 is the page number of customer list. The variable syntax shows that it takes the values from codeunit, and demo2 is the name of the codeunit.

Figure 7 – Creating a Page extension for insert a record in Dynamics Business Central on premises
Figure 7 – Creating a Page extension for insert a record in Dynamics Business Central on premises

Use F5 the shortcut Ctrl + G and select > AL: Publish. The customer page will open; go to Navigate → Customer → comments → InsertDemo(Action name).

Figure 8 – The action is added after comments, and name of the action is insert demo in Dynamics Business Central on premises
Figure 8 – The action is added after comments, and name of the action is insert demo in Dynamics Business Central on premises

A new record is added in the customer table, and the output is “Benjamin Franklin.”

Figure 9 – New record inserted in the customer table in Dynamics Business Central on premises
Figure 9 – New record inserted in the customer table in Dynamics Business Central on premises

Step 3: Modify a Record in the Customer Table

Create a new file to modify a record in the customer table. For creating the codeunit, use the shortcut or Snippet (tc). There are several options for selecting the tcodeunit.

Next, modify the record using the MODIFY function. Select the field you want to modify and write the new value in that field. The variable’s syntax shows the values are taken from the record, and customer is the table name.

Figure 10 – Creating a new file for a codeunit and modifying the customer name in Dynamics Business Central on premises
Figure 10 – Creating a new file for a codeunit and modifying the customer name in Dynamics Business Central on premises

Create a page Extension for modifying a record in the customer table. Use the shortcut or Snippet (tpage). There are several options for selecting the tpageext.

Here, you clearly state where you want to add this action and the action name. You can use 22 instead of “customer list” because 22 is the page number of customer list.  The variable syntax shows it takes the values from the codeunit, and demo3 is the name of the codeunit.

Figure 11 – Creating a Page extension for modifying a record in Dynamics Business Central on premises
Figure 11 – Creating a Page extension for modifying a record in Dynamics Business Central on premises

Use F5 Ctrl + G and select > AL: Publish. The customer page will open; go to Navigate → Customer → addafter → comments → ModifyAction(Action name).

Figure 12– The action is added after comments, and name of the action is modify Action in Dynamics Business Central on premises
Figure 12– The action is added after comments, and name of the action is modify Action in Dynamics Business Central on premises

The record is now modified; the output is now “Franklin.”

Figure 13 – Modified record in the customer table in Dynamics Business Central on premises
Figure 13 – Modified record in the customer table in Dynamics Business Central on premises

If you have any questions about Extensions or other Dynamics NAV or Business Central questions for any version, contact ArcherPoint.

Read more “How To” blogs from Archer Point for practical advice on using Microsoft Dynamics Business Central or NAV. If you are interested in NAV/Business Central development, check out our collection of NAV Development Blogs.

Trending Posts

Stay Informed

Choose Your Preferences
First Name
*required
Last Name
*required
Email
*required
Subscription Options
Your Privacy is Guaranteed