How to Repeat execute codeunit with changecompany?

julkifli33julkifli33 Member Posts: 1,073
Hi All,
I saw the steps to upgrade NAV from 2009R2 to NAV 2013
there is a step to do Task 4: Step 1 Data Conversion
Since I have more than 50 companies, is there a way i can create code to repeat this? -->
https://docs.microsoft.com/en-us/previous-versions/dynamicsnav-2013r2/hh166395(v=nav.71)
jipe2tek7hu0.png

same goes for this step --> https://docs.microsoft.com/en-us/previous-versions/dynamicsnav-2013r2/hh169256(v=nav.71)
Task 11: Step 2 Data Conversion

I tried using CHANGECOMPANY code, but it only works for Table but not codeunit
is there a way to do so?
Thanks before

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Short answer - you cannot.

    CHANGECOMPANY's scope is a record variable it has been called on. If you have two variables of the same type, and you call CHANGECOMPANY with different company name on one of them, the second would still 'point; to your current company

    The consequence of this behaviour is that If you have an upgrade codeunit running some code you would have to change it and add a call to CHANGECOMPANY on every single record variable, before the first use of it, and also after each RESET or CLEAR called with that rec variable.

    Also if your upgrade code calls some other functions or triggers in other objects, even as simple as VALIDATE(...) you would have to change all of those too to call CHANGECOMPANY with a proper company name in every object/function/trigger called directly or indirectly from your upgrade code
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • julkifli33julkifli33 Member Posts: 1,073
    Hi Slawek Guzek,
    thanks for the detail reply.
    so is there a way i can transfer data during NAV upgrade?
    or should it one by one?
    Thanks
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    It depends on what is in your upgrade codeunit.

    A safe and sure method is to do it one by one.

    If your upgrade codeunit does not call any functions / triggers in any other object then you could try to modify it and add a call to CHANGECOMPANY to all record variables. But if you miss one the code will probably not fail, just mess up the data.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • julkifli33julkifli33 Member Posts: 1,073
    I see.. actually its the NAV standard Upgrade Toolkit.
    upgrade to new version.
    i think safer to do it one by one then
    Thanks for the reply
Sign In or Register to comment.