How it works...

If you need some logic to be executed when your application is upgraded, then you need to create an upgrade codeunit. An upgrade codeunit is executed whenever an application is installed on a system that has had a previous version of the application installed.

You create an upgrade codeunit by following these steps:

  1. Create a new empty codeunit object.
  2. Assign the SubType = Upgrade attribute to the codeunit.

In the upgrade codeunit, you have access to a number of different triggers where you can place your code. The following triggers are available:

  • OnCheckPreconditionsPerCompany is used to determine whether any upgrade requirements are met for each company.
  • OnCheckPreconditionsPerDatabase is executed once during the upgrade process to determine whether any upgrade requirements are met. Only company-agnostic logic should go here.
  • OnUpgradePerCompany performs the upgrade logic in each company.
  • OnUpgradePerDatabase performs the company-agnostic upgrade logic.
  • OnValidateUpgradePerCompany is used to make sure that the upgrade was successful in each company.
  • OnValidateUpgradePerDatabase is executed once to make sure that the upgrade was successful. Only company-agnostic logic should go here.

When writing your upgrade logic, you can get information regarding the old version that was installed by using the ModuleInfo data type. With this, you can use the data version to determine the starting point for the upgrade, since, at the time the upgrade logic is executed, the version of the data represents the original version that's being upgraded.

More information can be found about the ModuleInfo data type at https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/moduleinfo/moduleinfo-data-type.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.93.222