Jul 29 2022
Pragma and Rulesets let you make or break the rules.
The AL Language extension (the language for developing applications for Microsoft Dynamics 365 Business Central) contains fourcode analyzers for analysis of your code at build time. “Code violations” are displayed in the Problem window when the code is analyzed. The information is valuable for identifying and jumping to Code Analysis Tool rule violations.
Now that you potentially have a list of “violations,” what if you want to treat them differently or even ignore them? Within the AL language, a few ways to control code analysis exist.
The al.codeAnalyzers setting allows you to specify which code analyzers are active for a particular environment, workspace or project. Code Analysis enforcement is only for the analyzers listed, leaving the option to only include the analyzers you want to enforce.
Rulesets are another option for specifying how code analysis reports the issues it encounters while analyzing AL code. The name and path for the ruleset file is set with the al.ruleSetPath setting. A Ruleset file is a JSON file that contains the Rule objects that define how to report a specific rule. In a rule, you specify the id of the diagnostic, the action (None, Hidden, Warning, Error) to take when the diagnostic is encountered, and a justification comment to note the rule. A Ruleset is applied globally within the scope of the setting.

A Ruleset file is a JSON file that contains the Rule objects that define how to report a specific rule.
Another option to control Code Analysis problems is the Pragma Warning Directive. The pragma warning instruction allows you to enable or disable specific warnings in a location of code. When disabling warnings with the pragma directive, the warnings are not reset back to the original state until you restore them.

An example of using the pragma directive to disable the rule id AA0001 for one section of code and restoring it.
There are several ways to enhance Code Analysis in AL, leaving you the flexibility to manage your code. Remember that if you submit an extension to AppSource, that Code Analysis is part of the technical validation, and your Rulesets may hide issues that cause the extension to fail validation.
Note: The code listed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2022 Wave 1
Jul 25 2022
Business Central Isolated Storage: Keep Out of my Data!
Microsoft Dynamics 365 Business Central Application Developers often need to store sensitive information their application uses. In earlier Dynamics NAV versions, developers often saved this data in table fields. The table field values were accessible to any other application or user that had access to the table. Information such as API keys, user credentials, or any additional information there is a desire not to have easily accessible was often stored and easily read from the table. Thankfully there is a more suitable way to do this in Business Central – Isolated Storage.
Isolated Storage in Microsoft Dynamics 365 Business Central is data storage that isolates data between extensions and even within the Extension. An application developer can store Key-Value Pairs in Isolated Storage and define the stored data’s scope (access level). Isolated Storage Key-Pairs’ DataScope can be limited to the Extension, a specific Company, a particular User, or a specific Company and User combination, providing an easy way for a developer to save values with a limited access scope.
Isolated Storage data isolation is accessed with the IsolatedStorage Data Type. The IsolatedStorage DataType provides methods to Set, Get, Delete or check if a Key Contains a value.
The Set Method saves a Key-Value Pair to Isolated Storage within the scope defined in the DataScope parameter.
The Get Method retrieves the Value for a Key in the scope defined by the DataScope parameter.
The Contains Method determines if the Key has a value in the scope defined by the DataScope parameter.
The Delete Method deletes the Value of a Key in the scope defined by the DataScope parameter.
For more information, see Isolated Storage.
Note: The code listed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2022 Wave 1
Jul 20 2022
Do Cops write tickets in AL?
The AL Language extension (the language for developing applications for Microsoft Dynamics 365 Business Central) contains four code analyzers for analysis of your code at build time.
The AppSourceCop analyzer enforces rules for extensions intended for listing in Microsoft AppSource. Whereas the CodeCop analyzer enforces AL Coding Guidelines and the UICop analyzer enforces rules for the Web Client. The PerTenantExtensionCop analyzer enforces individual tenant rules.
The al.enableCodeAnalysis setting is used to set the state of code analysis and the al.codeanalyzers setting specifies which of the code analyzers to enable.
Note: as with most settings, the al.enableCodeAnalysis and al.codeanalyzers settings may be set for a project, workspace, or development environment.
Once the code analysis is enabled and the code analyzers specified, the Rule Id and Title appear for each file, in the Problems window of the VS Code editor for any code “violations.”
It is possible to override the behavior of the code analyzer for specific Ids via the use of Pragma and Rulesets; that is for another time.
Note: The code listed in this article is for informational and demonstration purposes only.
Jul 19 2022
Make life easier with Visual Studio Code Snippets
Snippets in Visual Studio code are templates that make it easier to enter repeatable code patterns or blocks. They’re a helpful timesaver when developing applications. I have found significant time savings within Business Central with Snippets for page and table field templates.
Visual Studio Code has several built-in Snippets, extension publishers may include Snippets, and you can also define your own.
You can see a list of the snippets by the Insert Snipper command in the command palette or by typing one of the triggers for IntelliSense.
Snippets are in JSON, and you can define the Snippet scope as global or project. Each file can contain an unlimited number of snippets.
A Snippet is a named element containing a prefix, body, and description. The prefix of the Snippet defines the trigger words used to display the Snippet in IntelliSense. The body has the actual code for the Snippet, and the description includes the text shown in IntelliSense for the Snippet.
Within the body of the Snippet, you can define TabStops, where the editor cursor will move within a Snippet. You use $1, $2, etc., to specify the cursor location, with $0 being the last TabStop.
PlaceHolders are similar to TabStops, with the addition of a default value. The syntax for a placeholder is similar to the TabStop, with the addition of the default value ${1:Value}. PlaceHolders can be nested: {$1:Value1 ${2:Value2}}
Visual Studio Code contains a range of Variables for use within the body of the Snippet. There are editor Variables for inserting file information, date/time information, and some random values. One of my favorite variables is the Clipboard’s contents with the ${CLIPBOARD}, another is the currently selected text ${TM_SELECTED_TEXT}.
You can create your Snippet by selecting – Configure User Snippets from the settings menu and selecting either New Global Snippet or a New Project Snippet from the Command Palette. Once you have a Snippet file, you can also edit that directly.
For more information visit Snippets in Visual Studio Code
Note: The code listed in this article is for informational and demonstration purposes only.
Jul 18 2022
Business Central AL ModuleInfo
In the AL Language, the programming language behind Microsoft Dynamics 365 Business Central, the ModuleInfo Data Type provides information about an application. I have often used the ModuleInfo returned by the NavApp to check specific application version information.
The NavApp DataType includes information about a NavApp and has a few methods that retrieve a ModuleInfo for the Calling, Current or Specific application.
local procedure ModuleInfoDemo(ModuleInfoReqType: enum "DVLPR ModuleInfo ReqType");
var
ModuleInfo: ModuleInfo;
begin
case ModuleInfoReqType of
"DVLPR ModuleInfo ReqType"::Calling:
NavApp.GetCallerModuleInfo(ModuleInfo);
"DVLPR ModuleInfo ReqType"::Current:
NavApp.GetCurrentModuleInfo(ModuleInfo);
"DVLPR ModuleInfo ReqType"::Specific:
NavApp.GetModuleInfo('{c512d720-63b9-4b26-b062-a0c09b4ed322}', ModuleInfo);
end;
PopulatePageFields(ModuleInfo);
end;
local procedure PopulatePageFields(ModuleInfo: ModuleInfo)
var
i: Integer;
ModuleDependencyInfo: ModuleDependencyInfo;
DependencyNames: Text;
AppVersion,
DataVersion : Version;
begin
AppVersion := ModuleInfo.AppVersion;
DataVersion := ModuleInfo.DataVersion;
Clear(DependencyNames);
ModuleID := Format(ModuleInfo.Id);
ModuleName := ModuleInfo.Name;
ModulePublisher := ModuleInfo.Publisher;
ModuleAppVersion := Format(AppVersion);
ModuleDataVersion := Format(DataVersion);
ModulePackageId := Format(ModuleInfo.PackageId);
for i := 1 to ModuleInfo.Dependencies().Count() do begin
ModuleInfo.Dependencies.Get(i, ModuleDependencyInfo);
DependencyNames += ModuleDependencyInfo.Name + ',';
end;
ModuleDependency := DependencyNames;
end;
For more information, see ModuleInfo Data Type and NavApp Data Type
Jul 12 2022
My First Homegrown Vegetable
Jul 12 2022
View the Microsoft Dynamics 365 Business Central Tablet or Phone Client in a Browser
Microsoft Dynamics 365 Business Central allows users to access their data from a browser, tablet, or phone. The phone and tablet client provides users the flexibility to perform tasks while away from the browser.
There are several user experience differences between the different clients; The web client is intended for full application use, whereas the tablet and phone client are touch-optimized with the layout designed for the smaller screens.
In a mobile world, when developing a solution, it is crucial to consider the user experience with your Microsoft Dynamics 365 Business Central application on mobile devices. It is possible to open the tablet or phone client from a browser to make it easier to test a solution and consider the users’ experience. Depending on your application’s use and user experience, you may want a separate Role Center for mobile clients with pages with a carefully selected list of actions and fields.
To open the Microsoft Dynamics 365 Business Central tablet or phone client in a browser, append either “tablet” or “phone” after the instance of your Business Central installation.
For example:
Web Client:
http://bc20/BC/?tenant=default
http://bc20/BC/?tenant=default&page=22
Tablet:
http://bc20/BC/tablet/?tenant=default
http://bc20/BC/tablet/?tenant=default&page=22
Phone:
http://bc20/BC/phone/?tenant=default
http://bc20/BC/phone/?tenant=default&page=22
You can open the mobile client for a specific page, tenant, profile, company, report, or web client address by including the “tablet” or “phone” designator in the address after the instance name.
For more information, see the differences between the Business Central Mobile Apps.
Note: Information in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2022 Wave 1