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 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?
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;
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
I tested this code in a multple company database and it did work...
...
Thanks, if it works like this then it's great .
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.
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).
...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.
Answers
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?
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
Thanks, if it works like this then it's great .
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.
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).
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.
http://dynamicsuser.net/blogs/alexchow/ ... n-5-0.aspx
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book