Skip to content

How to: Customize Microsoft Dynamics Business Central On Premises Using AL Keywords 

How to customize Dynamics Business Central or NAV using AL Keywords

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 perform customizations using AL Keywords, including the terms CONFIRM, TESTFIELD, and COPYARRAY, making it easy and fast.

Using the CONFIRM Keyword

When you write code in Application Language (AL), there are times when you would like to interact with the user. For example, you can ask the user for a confirmation, provide some extra information, or let the user make a choice.

When you only want to execute certain parts of your code after the user confirmed an action should happen, you can use the CONFIRM function. You can use the CONFIRM function based on a string, which is the question you ask the user.

Confirm is used just like the MESSAGE function to display a message. However, unlike the MESSAGE function, the CONFIRM function has a required return value.

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

The CONFIRM function can be used in combination with the IF statement (as shown in Figure 2).

Figure 2 – Creating a new file for a codeunit and CONFIRM function cab be used in combination with the IF statement
Figure 2 – Creating a new file for a codeunit and CONFIRM function cab be used in combination with the IF statement

Create a page Extension for using the CONFIRM keyword in the vendor table. You can 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.

Figure 3 – Creating a page extension by using snippet tpageext
Figure 3 – Creating a page extension by using snippet tpageext

Press F5 or use the shortcut Ctrl + G and select AL: Publish. The Vendor list will open.

Go to Navigate > Vendor > Bank Accounts > addafter > comments > ConfirmAction(Action name).

Figure 4 – The ConfirmAction is added
Figure 4 – The ConfirmAction is added

When you want the NO button to have the default focus, you can add FALSE as a parameter.

Using the TESTFIELD Keyword

TESTFIELD tests whether a field contains a specific value. If the test fails, that is, if the field does not contain the specified value, an error message is displayed and a run-time error is triggered. This means that any changes that were made to the record are discarded.

If the value that you test against is an empty string, the field must have a value other than blank or 0 (zero).

Figure 5 – Creating a new file for a codeunit with the TESTFIELD Keyword
Figure 5 – Creating a new file for a codeunit with the TESTFIELD Keyword

Create a page Extension for using TESTFIELD keyword in the vendor 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. 

Figure 6 – Creating a page extension for a codeunit
Figure 6 – Creating a page extension for a codeunit

Press F5 or use the shortcut Ctrl + G and select AL: Publish. The Vendor list will open; go to Navigate > Vendor > Bank Accounts > addafter > comments > TestFieldAction(ActionName).

Figure 7 – TestFieldAction is added
Figure 7 – TestFieldAction is added

Figure 8 – Output of TESTFIELD keyword
Figure 8 – Output of TESTFIELD keyword

Using the COPYARRAY Keyword

The COPYARRAY function will create a new array based on an existing one. You can provide a starting position and optionally a length. If you don’t provide a length, it will copy all elements until the end, starting from the position.

Figure 9 – Creating a new file for a codeunit and performing COPYARRAY
Figure 9 – Creating a new file for a codeunit and performing COPYARRAY

Create a page extension for using the COPYARRAY keyword in the vendor 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.

Figure 10 – Creating a page extension for a codeunit
Figure 10 – Creating a page extension for a codeunit

Press F5 or use the shortcut Ctrl + G and select AL: Publish. The Vendor list will open; go to Navigate > Vendor > Bank Accounts > addafter > comments > ArrayAction(Action name).

Figure 11 – The ArrayAction is added
Figure 11 – The ArrayAction is added

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 ArcherPoint 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/BC Development Blogs.

Blog Tags: 
Read ArcherPoint's Blog Follow us on Twitter Follow us on Facebook Follow us on LinkedIn Link to our RSS feed Watch us on YouTube
Get Help Now