MS D365BC Workshop Building Apps
MS D365BC Workshop Building Apps
MS D365BC Workshop Building Apps
Microsoft Code
On Premise
Dynamics NAV Modifications
Tomorrow
Dynamics
365 Code
SaaS
Business Extensions
Central
Customizations
Traditional way Extensions way
ADDON EXTENSIONS
Events
NAV LOCALIZATION NAV LOCALIZATION
LAYER LAYER
HOW
Codeunit 1: no more!
• LogInManagement
• ReportManagement
• Application System Constants
• Conf./Personalization Mgt.
• TextManagement
• AutoFormatManagement
• CaptionManagement
• GlobalTriggerManagement
• SaaS Log In Management
• Company Information
• Custom Report Layout
• ODataUtility
• Data Upgrade Mgt.
OnCheckPreconditionsPerCompany Codeunit<Data Upgrade Mgt.>.PROCEDURE<OnCheckPreconditionsPerCompany>
OnCheckPreconditionsPerDatabase Codeunit<Data Upgrade Mgt.>.PROCEDURE<OnCheckPreconditionsPerDatabase>
OnInstallAppPerCompany NOT AVAILABLE ANYMORE
OnInstallAppPerDatabase NOT AVAILABLE ANYMORE
OnUpgradePerCompany Codeunit<Data Upgrade Mgt.>.PROCEDURE<OnUpgradePerCompany>
OnUpgradePerDatabase Codeunit<Data Upgrade Mgt.>.PROCEDURE<OnUpgradePerDatabase>
OnValidateUpgradePerCompany Codeunit<Data Upgrade Mgt.>.PROCEDURE<OnValidateUpgradePerCompany>
OnValidateUpgradePerDatabase Codeunit<Data Upgrade Mgt.>.PROCEDURE<OnValidateUpgradePerDatabase>
OnAfterAutoFormatTranslate Codeunit<AutoFormatManagement>.PROCEDURE<OnAfterAutoFormatTranslate>
OnAfterCaptionClassTranslate Codeunit<CaptionManagement>.PROCEDURE<OnAfterCaptionClassTranslate>
OnAfterCompanyClose Codeunit<LogInManagement>.PROCEDURE<OnAfterCompanyClose>
OnAfterCompanyOpen Codeunit<LogInManagement>.PROCEDURE<OnAfterCompanyOpen>
OnAfterFindPrinter Codeunit<ReportManagement>.PROCEDURE<OnAfterGetPrinterName>
Codeunit<GlobalTriggerManagement>.PROCEDURE<OnAfterGetDatabaseTableTriggerSetup
OnAfterGetDatabaseTableTriggerSetup
>
http://aka.ms/bcsandbox
http://trials.dynamics.com (sandbox)
https://hub.docker.com/r/microsoft/bconprem
Business Central on-premise
AL Language
Visual Studio Code and the AL Language extension lets you do the following tasks:
• Create new files for your solution
• Get assistance with creating the appropriate configuration and setting files
• Use code snippets that provide templates for coding application objects
• Get compiler validation while coding
• Press F5 to publish your changes and see your code running on NAV
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-get-started-container-sandbox
Dynamics 365 Business Central: Sandbox
Environment totally isolated from a production instance where you can do development, testing, demos and
playing with the service without affecting the real production data.
Visual Studio Code only Visual Studio Code. Supports also C/SIDE and SQL Management Studio
Production data manually uploaded using Configuration Packages Production data manually uploaded using Configuration Packages
Costs are part of the Business Central subscription Free if locally-hosted, Azure costs if hosted on Azure VM.
You can reset your online sandbox environment at any time. Remember that resetting the sandbox will
completely remove and recreate it with demonstration data
Dynamics 365 Business Central Sandbox
Azure-hosted Sandbox:
What is Docker?
Add Application /
Change settings Partner image or partner instance
Override scripts
+ Country database microsoft/dynamics-nav:ver[-rel]-loc
Run Install Scripts Specific
microsoft/dynamics-nav:ver[-rel]
+ parts of NAVDVD
+ Installation scripts
microsoft/dynamics-nav:generic Generic
+ SQL Express + IIS
After switching:
D365BC on Docker (5)
From Command Prompt (running as Administrator):
OR
For an object:
1. Properties
2. Object-specific constructs such as:
1. Table fields
2. Page layout
3. Actions
3. Global variables
1. Labels (old Text Constants)
2. Global variables
4. Methods
Referencing
var
Customer: Record Customer;
Variable naming
// space
Internal: on-premise (target = Internal in app.json These settings affects possible features (File
External: SaaS (target = Extension in app.json) Management, DotNet, Excel Buffer)
D365BC: adding objects to Search
• You enable a page or report to be available through Search in Dynamics 365 Business Central using
the UsageCategory setting
• If the UsageCategory is set to None, or if you do not specify UsageCategory, the page or report will not show
up when you use the Search functionality
• The values for the UsageCategory property are:
• None
• Lists
• Tasks
• ReportsAndAnalysis
• Documents
• History
• Administration
AL: fields missing on Dynamics 365 Business Central
With D365BC, always add ApplicationArea
The app.json file contains a setting called showMyCode, which controls whether it is possible to debug into
the extension, when that extension is taken as a dependency
If you want to allow debugging into an extension to view the source code,
you can add the showMyCode property in the app.json file (the manifest) and set the property value to true
"showMyCode": true
AL Code Analysis
Four Code Analyzers available:
• CodeCop is an analyzer that enforces the official AL Coding Guidelines.
• PerTenantExtensionCop is an analyzer that enforces rules that must be respected by extensions meant to be
installed for individual tenants.
• AppSourceCop is an analyzer that enforces rules that must be respected by extensions meant to be published
to Microsoft AppSource.
• UiCop is an analyzer that enforces rules that must be respected by extensions targeted for Web Client
development
• Full list:
https://docs.microsoft.com/en-gb/dynamics365/business-central/dev-itpro/developer/datatypes/devenv-text-data-type
List and Dictionary data type
• When you publish your extensions, you must do the extension that are depended on first (e.g. Parent). If you try and
publish the extension with the dependency first (e.g. Child), it will error stating that references do not exist in the
database.
• When you remove extensions, you must remove the extensions that have the dependencies first (e.g. Child)
Extensions Translations (XLIFF)
No more CaptionML!
Extensions Translations (XLIFF)
Use Caption and ToolTip:
Extensions Translations (XLIFF)
• Virtaal
https://virtaal.translatehouse.org/
Extensions: field deletion
Launch.json: Default: schemaUpdateMode: Synchronize (no data loss every time you publish an extension)
In your local sandbox environment you can “clean” your environment in the following ways:
• From Visual Studio Code by using “schemaUpdateMode”: “Recreate” in launch.json
• From Powershell by executing the following command:
Sync-NavApp -Name <name of extension> -Version <Version of extension> -Tenant <Tenant name> -Mode Clean
In a production environment, once an extension is synchronized to a tenant then all the next versions
(upgrades) must have a schema that is backward compatible.
1. Mark the changed field with ObsoleteState = Pending or Removed.
2. Create a new table (or new fields or keys) with the new data type or values.
3. Create an Upgrade codeunit that moves the old data to the new data.
4. Use the new field or keys.
Extensions: schema changes
The ObsoleteState property can have these values:
• Pending: the element will be obsolete in a future release. This setting has no
effect on the current use of the table, field, or key in code.
• Obsolete or Removed: the element is not deleted from the database;
however, references to the the element in code are only allowed in upgrade
codeunits. References from other objects will result in a runtime error.
Debugging Extensions in D365BC sandbox
To enable AL debugging from VS Code we need to change the NetFx40_LegacySecurityPolicy setting in the
Microsoft.Dynamics.Nav.Server.exe.config file (in the Dynamics NAV service install directory) to
false:
<NetFx40_LegacySecurityPolicy enabled="false"/>
Use generatesymbolreference = YES as a command line argument each time you start
finsql.exe to have all compilations add a symbol reference to the NAV App Object Metadata table
(default = NO):
finsql.exe generatesymbolreference=yes
At server level, the Enable Symbol Loading at Server Startup flag must be enabled to allow any
symbol generation. If the setting is not enabled, the generatesymbolreference setting does
not have any effect.
DAY 2
Stefano Demiliani
Microsoft Technical Workshop [email protected]
@demiliani
http://www.demiliani.com
Source Control Mangement
• Why?
• AL is file based, so it is much simpler to do SCM
• There is no database anymore, only a compiled app
• Useful when working in teams (co-authoring, code reviews)
• Tie into daily builds (automated tests, continuous integration / continuous
deployment)
• + Daily builds
• + Discard changes
• + History
• - No guarantee that the branch is stable
• + x months cycles
• + hotfix existing releases
Installing Extensions: custom operations
• You can perform actions on data when installing an extension (populating tables, checks etc.).
• Install logic in written in an install codeunit. This is a codeunit that has the SubType property is set
to Install.
• You can have more than one install codeunit. Execution order is not guaranteed.
Installing Extensions: custom operations
Install codeunit syntax:
Uninstalling Extensions
Uninstalling an extension will not remove the data. Data are moved on archived tables :
trigger OnUpgradePerCompany()
var
archivedVersion : Text;
begin
archivedVersion := NAVAPP.GetArchiveVersion();
if archivedVersion = '1.0.0.1' then begin
NAVAPP.RESTOREARCHIVEDATA(DATABASE::"My Table 1");
NAVAPP.DELETEARCHIVEDATA(DATABASE::"My Table 2");
end;
end;
Upgrading Extensions
• If there are no data changes between the versions of your extension, then you do not need to write
upgrade code.
• Upgrade logic must be written in an upgrade codeunit, which is a codeunit whose SubType property is
set to Upgrade.
• Syntax:
Upgrading Extensions
• PerCompany triggers are run once for each company in the database, where each trigger is
executed within its own system session for the company.
• PerDatabase triggers are run once in the entire upgrade process, in a single system session that
does not open any company.
Upgrading Extensions
Each extension version has a set of properties that contain information about the extension. These
properties are encapsulated in a ModuleInfo data type:
In VSCODE open the report and specify RDLC Layout property value to the path of your RDLC layout
DotNet with Dynamics 365 Business Central
Available in Preview only for On-Premise deployment
DotNet with Dynamics 365 Business Central
Declare a dotnet package:
dotnet
{
assembly(YOURASSEMBLY)
{
type(YOURDOTNETTYPE; ALIAS) {}
}
}
Isolated Storage
Data storage that provides isolation between extensions, so that you can keep keys/values in one
extension from being accessed from other extensions.
Isolated Storage
The DataScope Option Type identifies the scope of stored data in the isolated storage.
DataScope is an optional parameter and if it is not passed the value would be Module.
Member Description
Module Indicates that the record is available in the scope of the app(extension) context.
Company Indicates that the record is available in the scope of the company within the app context.
User Indicates that the record is available for a user within the app context.
CompanyAndUser Indicates that the record is available for a user and specific company within the app context.
API: new way for integration
Dynamics 365 Business Central exposes REST API for integration with other services.
Dynamics 365 Business Central: there are two different ways to connect to and authenticate against the APIs:
• Use Azure Active Directory (AAD) based authentication against the common API
endpoint: https://api.businesscentral.dynamics.com/v1.0/api/beta
• Use basic authentication with username and password (a so-called web service access key) against the
common API endpoint that includes the user domain, for
example https://api.businesscentral.dynamics.com/v1.0/cronus.com/api/beta.
Production: you must use Azure Active Directory (AAD)/OAuth v2 authentication and the common
endpoint https://api.businesscentral.dynamics.com/v1.0/api/beta.
In Dynamics NAV, search for API Setup and then choose the related link.
On the API Setup page, choose the Integrate APIs button. This will start a process of populating all the integration tables
with records for all APIs.
All standard APIs are pages in range 5470 - 5528 with page type = API. Use them as templates to create your
own APIs.
shipmentMethods salesCreditMemos
taxAreas salesCreditMemoLines
taxGroups
unitsOfMeasure
{
"invoiceDate": "2016-07-26",
"dueDate": "2016-08-26",
"customerId": "653053b1-d580-4102-845f-00df29a77e1e",
"salesInvoiceLines" : [
{"itemId":"5b0b9c1c-312d-4809-96b2-056690a11057", "quantity": 4},
{"itemId":"ad7220e5-8149-4cf0-a1e6-07d2bbbf414c", "quantity": 1}
]
}
Custom API endpoints
Production Sandbox
https://api.businesscentral.dynamics.com/v1.0/ https://api.businesscentral.dynamics.com/v1.0/
The list of all custom APIs <your domain>/api/<ApiPublisher> <sandbox tenant id>/sandbox/api/<ApiPublisher>
/<ApiGroup>/<ApiVersion> /<ApiGroup>/<ApiVersion>
https://api.businesscentral.dynamics.com/v1.0/ https://api.businesscentral.dynamics.com/v1.0/
The list of companies <your domain>/api/<ApiPublisher> <sandbox tenant id>/sandbox/api/<ApiPublisher>
/<ApiGroup>/<ApiVersion>/companies /<ApiGroup>/<ApiVersion>/companies
https://api.businesscentral.dynamics.com/v1.0/ https://api.businesscentral.dynamics.com/v1.0/
<your domain>/api/<ApiPublisher> <sandbox tenant id>/sandbox/api/<ApiPublisher>
The list of your entities
/<ApiGroup>/<ApiVersion>/companies /<ApiGroup>/<ApiVersion>/companies
(<companyId>)/<entitySetNames> (<companyId>)/<entitySetNames>
Custom API: rules
Azure AD Authentication
Support Read/Write of Business Central data
Designer first
Pre-built templates
Ready-made actions
Designed via browser or mobile app
To master all these topics…