Hi Readers,
Business Central gives you a facility to perform certain operations while you install the extension. This can be done with the help of an Install codeunit. You can also use these codeunits if you want to test something during the extension installation.
Some of the examples can be populating empty records with data, service callbacks and telemetry, version checks, and messages to users.
How to create it?
For a codeunit to be of type 'Install', you need to define the SubType.
There are two triggers:
1. OnInstallAppPerCompany() - Includes code for company-related operations. Runs once for each company in the database.
2. OnInstallAppPerDatabase() - Includes code for database-related operations. Runs once in the entire install process.
Note: The codeunit triggers if the app is published for the first time.
Example:
Scenario:
Say, you have a table in your extension and during installation, you want to insert some values to your table (table has an InsertRecords() function). You can do as mentioned below:
You can check this installation in different environments (Install app for the first time), for it to trigger:
1. Sandbox:
VSCode > AL:Publish without debugging (Ctrl+F5)
2. Online Sandbox:
VSCode > AL:Publish without debugging (Ctrl+F5)
3. Online Business Central Production:
>Web client > Extensions Page >Upload .app file
No comments:
Post a Comment