data update at two company

GRUBBYFANSGRUBBYFANS Member Posts: 154
For example when i updated itemno under A company,Also I'd like to updated itemno under B company,
Do you know the method? :(

Answers

  • DigiTecKidDigiTecKid Member Posts: 46
    Have you researched the CHANGECOMPANY command? Look in the C/SIDE Reference Guide.
    Something like:
    If Item1.RENAME("No.", '111222333') THEN BEGIN
    CLEAR(Item2);
    Item2.CHANGECOMPANY('COMPANY B');
    IF Item2.GET(Item1."No.") THEN
    Item2.RENAME("No.", Item1."No.");
    END;

    I believe the company name is case sensitive as well so use the exact name for "Company B".
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DigiTecKid wrote:
    Have you researched the CHANGECOMPANY command? Look in the C/SIDE Reference Guide.
    Something like:
    If Item1.RENAME("No.", '111222333') THEN BEGIN
    CLEAR(Item2);
    Item2.CHANGECOMPANY('COMPANY B');
    IF Item2.GET(Item1."No.") THEN
    Item2.RENAME("No.", Item1."No.");
    END;

    I believe the company name is case sensitive as well so use the exact name for "Company B".

    have you actually tried this #-o Will it actually change the records in the correct database?
    David Singleton
  • GRUBBYFANSGRUBBYFANS Member Posts: 154
    Thank you,I will try run this code,let me see
  • DigiTecKidDigiTecKid Member Posts: 46
    I have used something similar before. Although in my typing haste my code example was not exact. I added an extra field to the RENAME command (Item1.RENAME("No.", '111222333')) when it should have just been Item1.RENAME('111222333') (after getting the item to be renamed). I also specified Item1."No." in the RENAME of Item2 (Item2.RENAME("No.", Item1."No.")) which in the code example had already been renamed. It should have been just Item2.RENAME(OldItemNoValue)

    I tested this code in a multple company database and it did work...

    IF Item1.GET('AUD-8450 NEW') THEN
    IF Item1.RENAME('111222333') THEN BEGIN
    CLEAR(Item2);
    Item2.CHANGECOMPANY('Company B');
    IF Item2.GET('AUD-8450 NEW') THEN
    Item2.RENAME(Item1."No.");
    END;
  • GRUBBYFANSGRUBBYFANS Member Posts: 154
    DigiTecKid wrote:
    I have used something similar before. Although in my typing haste my code example was not exact. I added an extra field to the RENAME command (Item1.RENAME("No.", '111222333')) when it should have just been Item1.RENAME('111222333') (after getting the item to be renamed). I also specified Item1."No." in the RENAME of Item2 (Item2.RENAME("No.", Item1."No.")) which in the code example had already been renamed. It should have been just Item2.RENAME(OldItemNoValue)

    I tested this code in a multple company database and it did work...

    IF Item1.GET('AUD-8450 NEW') THEN
    IF Item1.RENAME('111222333') THEN BEGIN
    CLEAR(Item2);
    Item2.CHANGECOMPANY('Company B');
    IF Item2.GET('AUD-8450 NEW') THEN
    Item2.RENAME(Item1."No.");
    END;

    yeah,the code was successful,very thank you DigiTecKid
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DigiTecKid wrote:
    ...

    I tested this code in a multple company database and it did work...
    ...

    Thanks, if it works like this then it's great :D .

    Obviously it requires that there is no code in OnRename, but that can be worked with. I had tried this a long time ago, and it hit the wrong tables (change in source company not destination company) in some cases, but I bet that was because those tables triggered the OnRename.
    David Singleton
  • DigiTecKidDigiTecKid Member Posts: 46
    David,

    I believe you are correct. I was assuming (dangerously) that the Item table OnRename trigger in question did not have any modifications that made calls to other tables. In that case those calls would be to data in the company the user is logged into NOT the data in the company specified in the CHANGECOMPANY command. This could give very unexpected/unwanted results.

    I second guessed myself and ran another test to make sure the table relationships for the item number were updated in the "B" company when the RENAME is done on the record variable after the CHANGECOMPANY was made to company "B". The sales lines (order, shipment and posted invoice) were all changed as well as the corresponding purchase side records. So while code in the RENAME trigger that performs record calls may get data from the wrong company (the company the user is in when the function is called), the internal RENAME table relationship updates ARE done in the correct company (the company specified in the CHANGECOMPANY command).
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DigiTecKid wrote:
    ...I second guessed myself and ran another test to make sure the table relationships for the item number were updated in the "B" company when the RENAME is done on the record variable after the CHANGECOMPANY was made to company "B"....

    Thanks this is great to know.
    \:D/

    I am also wondering if maybe this is something they fixed at some stage. I know that in earlier versions of NAV there were problems with drilling down to flow fields after change company, maybe it was fixed all at the same time.
    David Singleton
Sign In or Register to comment.