Wednesday, August 26, 2020

Know what an Install Codeunit does and how to execute it in Microsoft Dynamics 365 Business Central

 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


Hope this blog was helpful. Stay tuned for another blog, next week. :) 
Check out other blogs, if you haven't already. 

Please suggest what else do you want me to blog about. Keep following and supporting!

You can also email me at jyotsnaoberainav@gmail.com

Also, visit my website JONAV if you need help with any NAV/BC Services!

Thank you! 

No comments:

Post a Comment