Monday, September 7, 2020

Know what an Upgrade 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 upgrade the extension i.e, changes were made to your extension and you would want to publish it. This can be done with the help of an Upgrade codeunit. There are operations that can be performed while you modify an extension and want to check something at that time. 

Some of the examples can be updating version of an app,  modifying records in a table, inserting value to a field if a new field was created in the extension. 

How to create it? 

For a codeunit to be of type 'Upgrade', you need to define the SubType. 

These are the triggers:

OnCheckPreconditionsPerCompany()  and OnCheckPreconditionsPerDatabase():

Used to check that certain requirements are met before the upgrade can be run.

OnUpgradePerCompany() and OnUpgradePerDatabase():

Used to do the actual upgrade.

OnValidateUpgradePerCompany() and OnValidateUpgradePerDatabase():

Used to check that the upgrade was successful.

Note: Upgrade codeunit will trigger when we Publish our extension for the second time with updated version id. 

Example:

Scenario:

A new version of the extension wherein you want to remove any special characters from the Customer name. Following is the code:

Update it by increating the version: app.json > “version”: “2.0.0.0”

1. Online Sandbox:

VSCode > AL:Publish without debugging (Ctrl+F5)

2. Online Business Central Production:

>Web client > Extensions Page >Upload .app file

Source Reference: Dmitry Katson A big Thanks!

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! 

2 comments:

  1. Thank you!
    Do check other blogs if you haven't already!

    ReplyDelete
  2. SMB ERP Solution is a Microsoft Silver Partner. We provide Supply Chain Management Solutions, Microsoft NAV, Microsoft Dynamics NAV, Microsoft Dynamics Business Central. Contact us info@smb-erpsolutions.com for more details. Check out our website for more detials- Dynamics NAV Upgrade

    ReplyDelete