Dynamics 365 Business Central: AL Snippets

Dynamics 365 Business Central

Hello everyone.
Yesterday I shared two extension packs that will makes you more productive.
For details: Dynamics 365 Business Central: Two Extension Packs that will make you more productive
Today I want to talk about the Code Snippets in Business Central.

Code snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements. Each language provides default language snippets. AL Language is the same, you can access to various AL snippets that will give you a template for a specific object type when you develop Business Central.

Examples of AL Snippets
The following is a non-comprehensive list of the snippets that you can use in the AL.

Type…To get a…
tassertAssert error structure
tcaseofCase of structure
tcaseelseCase else structure
tcodeunitCodeunit object structure
tfieldTable field structure
tfieldpagePage field structure
tforFor structure
tifIf structure
tifelseIf else structure
tpagePage object structure
tpageextPage extension structure
tprocedureMethod structure
tqueryQuery object structure
trepeatRepeat until structure
treportReport object structure
ttableTable object structure
ttableextTable extension structure
ttriggerTrigger structure
twithdoWith do structure
twhileWhile structure
txmlportXMLport object structure
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-syntax#ExamplesOfSnippets

So how to use it.
There are two ways:

1. Start typing the snippet prefix
For example: Type “ttable”, then click it.

Template of table will be added.

2. Run Command Palette (Ctrl + Shift + P) and select “Insert Snippet“, then select snippet from the list.

If you are good at using snippets, you can save a lot of time during development.

Actually you can also create snippets to fit your requirements using Visual Studio Code.
Let’s try it.
Run Command Palette (Ctrl + Shift + P) and select “Preferences: Configure User Snippets“.

Select “New Global Snippets file…”

Enter the name of new snippet.

Enter “prefix”, “body” and “description”.

You can use it after saving.

PS:
The user-defined snippets are stored in “C:\Users\<username>\AppData\Roaming\Code\User\snippets”

The default snippets are stored in “C:\Users\<username>\.vscode\extensions\<extensionname>\snippets”

Please do not delete and change the default snippets.
Yes, you can change the snippet in the extension folder directly, but when the extension is updated or reinstalled, it will overwrite the snippets so you will lost your modification.

End.

Hope this will help.
Thanks.

コメント

タイトルとURLをコピーしました