NAV2018: VSCode UpgradePerCompany/Database

maze93maze93 Member Posts: 24
Hi all,

It seems that when you republish an extension from VSCode (CTRL +F5) all the data inside the tables of your extension is removed.
I've read all there is to read about upgrade codeunits but it does not seem that OnNavAppUpgradePerCompany and OnNavAppUpgradePerDatabase works yet for extensions (with the use of NAVAPP.RestoreArchiveData of course)?

Last update I could find about this can be found here: https://github.com/Microsoft/AL/issues/62

Does anyone else have any information when we can expect this feature? If we can't upgrade our data then we can't republish any extensions (even if both publications are identical) which means we can't use extensions :-)

Thank you!

Regards from Mattias

Answers

  • DenSterDenSter Member Posts: 8,304
    That issue is not about upgrade codeunits but about running the extension in a dev environment. Currently when you run, then add some data, then run again, the app loses its data. In that case, the upgrade codeunit does not run.

    If you deploy a new version of your .app file, and you run the proper powershell to deploy it (publish-navapp, then sync-navapp, then start-navappdataupgrade), the upgrade codeunit does run. I ran one myself this morning and it ran as expected. Here's a link that explains the process: https://docs.microsoft.com/en-us/dynamics-nav/developer/devenv-upgrading-extensions
  • maze93maze93 Member Posts: 24
    @DenSter so you mean I shouldn't deploy from VsCode with CTRL F5 bit use Powershell instead? Do you think it would work if i deploy through VsCode and then run sync and dataupgrade from Powershell? Or only via Powershell?

    Thanks!
  • maze93maze93 Member Posts: 24
    Has anybody got any more information regarding this? Do we know when we can expect the issue to be resolved? Since it was not resolved in CU1, hopefully in CU2? Seems odd that Microsoft forgets to implement one of the most needed functions...
  • DenSterDenSter Member Posts: 8,304
    I don't think it's a matter of them *forgetting* about it, and it's a matter of your point of view whether it is even considered to be *an issue*, maybe from their point of view it works exactly the way they want it to work. It kind of makes sense to redeploy rather than upgrade, so that you are totally free to make any type of destructive change in your dev environment.

    If you want the upgrade codeunit to run, you have to run it through powershell. Deploying your app from VSCode does not run the upgrade codeunit. It does run the Install codeunit though, so if you need some data setup you can put that there.
  • DenSterDenSter Member Posts: 8,304
    Update: they put in a new property for launch.json called 'schemaUpdateMode'. Set it to 'recreate' and it will rebuild the table and you lose your data. Set it to 'Synchronize' and you get to keep your data between F5's. Very useful :)
  • maze93maze93 Member Posts: 24
    Hi @DenSter

    I wonder if they will put in a "Force"-property to not loose any data. We will see...
  • DenSterDenSter Member Posts: 8,304
    I don't understand your point. You keep your data by setting the schemaUpdateMode to Synchronize. Not sure what that property would do in addition to that
  • maze93maze93 Member Posts: 24
    Hi @DenSter

    In cases where you need to i.e. remove a field from a table, change the field type or such things, but want to keep the data. I get that you can use an upgrade codeunit for this, so it is possible to solve but that is what I mean.

    Rgds from Mattias
  • DenSterDenSter Member Posts: 8,304
    I still don't get it. You need a field to keep data. Doesn't make sense to remove the field if you want to keep the data. Anyway, the SchemaUpdateMode property is not relevant for actual upgrade scenarios, it's only relevant for how the app deals with tables.
  • maze93maze93 Member Posts: 24
    Hi. The problem is that recreate removes all data from all fields.
    I want to remove a field without removing the data from the other fields I have added. I don't know if I can be any more clear than that...

    Anyways, we will see what happens in the future, hopefully this scenario will be solved :)
  • DenSterDenSter Member Posts: 8,304
    I'll repeat it once again: Set the SchemaUpdateMode to 'Synchronize' and it will keep the data when you rebuild your solution
  • maze93maze93 Member Posts: 24
    Hi Denster, it is not that I don't get what you mean but you can not use Synchronize if you are removing a field from a solution ,then you need to use Recreate, which means it will empty out all of your other tables in the solution too. This is the problem.

    To be more precise:
    I have 3 tables with 3 fields in each. First I publish them all, then I enter some information into the tables. Then I want to remove one of the fields in table no. 1. If I do this, then I will have to use recreate. This does not only mean that all data in table no. 1 will be removed, but also that the data in table 2 and 3 will be removed. In this case I would like to remove ONLY the field and the data stored in the field, but keep all other data intact.

    Fortunately, this can now be handled with upgrade codeunits so it is not a big problem anymore, however I would still like to see a "force"-option to remove a field without all other data being removed.

    Rgds from Mattias
  • RedFoxUARedFoxUA Member Posts: 21
    edited 2018-11-27
    Good day Mattias.

    if I understood correctly you found a solution how to delete 1 field from 1 table only and have not use "schemaUpdateMode"::Recreate option?
    Could you help me (I tried to write upgrade codeunit (and install also) too, but no luck :( ) with information?
    I checked MS-site and can't find answer too..

    Thank you in advance for your help.
    Regards,
    Yuriy Golyachuk, NAV Solutions Specialist & Developer
    Skype: RedFoxUA
Sign In or Register to comment.