web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

Upgrading extension from Visual Studio Code

(0) ShareShare
ReportReport
Posted on by 150

I'm following this guide to build an app with the Business Central Sandbox. I'm stuck at the last part of it, where it explains how to write code for upgrades. The problem is it says to use cmdlets, but I believe this is only for the on-premise version? This seems to confirmed by this question on the AL GitHub. So how can this be done with the sandbox? The error I'm getting when compiling/running is:

The request for path /v1.0/sandbox/dev/apps?SchemaUpdateMode=synchronize failed with code 422. Reason: Cannot install the extension [Project Name] by [Publisher Name] 1.0.0.1 for the tenant [Tenant] because an earlier version was already installed. Run Start-NAVAppDataUpgrade to upgrade the extension.

But how do I run Start-NAVAppDataUpgrade?

Categories:
  • Stefano Demiliani Profile Picture
    37,172 Most Valuable Professional on at

    For upgrading extensions you need to create an upgrade codeunit only if you need to perform actions during the upgrade, such as data management on pre-condition check. On the online platform, the upgrade process (execution of your upgrade codeunit) is automatically triggered by the platform when installing the extension.

    On the local sandbox, the upgrade process can be done:

    1) from VS Code if you don't have performed schema changes from the previous version

    2) Executing some powershell commands if you have schema or data changes:

    Publish-NAVApp

    Sync-NAVApp

    Start-NAVAppDataUpgrade

  • SSDev1 Profile Picture
    150 on at

    I am using the online platform. I added an upgrade codeunit and incremented the version in app.json, but I get the error I mentioned above, so it doesn't seem to be triggering it automatically.



    "The request for path /v1.0/sandbox/dev/apps?SchemaUpdateMode=synchronize failed with code 422. Reason: Cannot install the extension [Project Name] by [Publisher Name] 1.0.0.1 for the tenant [Tenant] because an earlier version was already installed. Run Start-NAVAppDataUpgrade to upgrade the extension."
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,172 Most Valuable Professional on at

    What are the modification done from the previous version? Try to use "schemaUpdateMode": "Recreate" in launch.json when publishing the extension from VS Code.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,172 Most Valuable Professional on at

    What are the modification done from the previous version? Try to use "schemaUpdateMode": "Recreate" in launch.json when publishing the extension from VS Code if you can admit data loss.

  • SSDev1 Profile Picture
    150 on at

    Using schemaUpdateMode Recreate allows it to publish, but it doesn't seem to be running the upgrade codeunit. Is this because using recreate means it's not actually upgrading the extension, but just recreating it? Also, I don't mind losing data at the moment, but this could be an issue in the future for something else.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,172 Most Valuable Professional on at

    Yes, with recreate the update is not triggered. If you want to trigger the upgrade, you should write an Upgrade codeunit as you've done.

    Try this thing. Go to the Extensions page on Online Sandbox and you should have the new app version published, but not installed. If so, just click Install.

  • SSDev1 Profile Picture
    150 on at

    This seems to be the way to do it. Run in VS Code, get the error, go the tenant's extensions page and install it, then it runs the upgrade codeunit. Maybe something has to be fixed to prevent that error from happening in the first place though.

  • Community Member Profile Picture
    on at

    Hi,

    I have the same problem. I created a sandbox on BC Online from with the customer's data. On the live enviroment there is an old customerApp (v. 1.0.0.10005).

    Now, I published a new fatherApp and a new version customerApp (v. 1.1901.2100.1007) and the new version of the customerApp now depends from the fatherApp.

    The fatherApp is installed and the customerApp no. The error by the VS Code is "The request for path /v1.0/sandbox/dev/apps?SchemaUpdateMode=synchronize failed with code 422. Reason: Cannot install the extension [Project Name] by [Publisher Name] 1.0.0.1 for the tenant [Tenant] because an earlier version was already installed. Run Start-NAVAppDataUpgrade to upgrade the extension."

    From the Extension Management on BC, I see the new version of customerApp published but not-installed and I didn't see the old version of customerApp. If I try to Install the new version BC return this error: "Multiple published extensions match the specified parameter values. You must specify more information to indicate which extension to use."

    In the customerApp there is this upgrade codeunit:

    codeunit 58001 "Customer Upgrade Codeunit"

    {

       subtype = Upgrade;

       trigger OnValidateUpgradePerCompany();

       var

           MyAppInfo: ModuleInfo;

           CustomerSetup: Record "Customer Setup";

       begin

           if NavApp.GetCurrentModuleInfo(MyAppInfo) then begin

               Clear(CustomerSetup);

               if NOT CustomerSetup.get then begin

                   CustomerSetup.Init;

                   CustomerSetup.Insert;

               end;

               CustomerSetup.AppID := MyAppInfo.Id;

               CustomerSetup.AppName := Format(MyAppInfo.Name, 250);

               CustomerSetup.AppPublisher := Format(MyAppInfo.Publisher, 250);

               CustomerSetup.AppVersion := Format(MyAppInfo.AppVersion, 50);

               CustomerSetup.AppDataVersion := Format(MyAppInfo.DataVersion);

               CustomerSetup.Modify(true);

           end;

       end;

    }

    In the customerApp new version, I added one new table, very easy extension, and I deprecated a table created in the old version of customerApp with the property ObsoleteState = Removed;

    Could you help me?

    Thank you,

    Roberto.

  • Community Member Profile Picture
    on at

    According Microsoft, this should be solved in the fall release:

    github.com/.../4507

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans