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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Copy item to another company in coding

(0) ShareShare
ReportReport
Posted on by 2,013

Hi,

May I know how to copy item (InventTable, InventTableModule, InventItemLocation) to another company / dataarea.

How to change the dataarea because after I copied my InventTable, changecompany, and try to insert, the dataarea will follow the first company which is will produce error because duplicate record.

 Thanks,

Axl

 

 

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    Use this code to insert the records in another company:

    changecompany('dmo')

    {

           //Place your code here of insertion or any operation.

    }

    Regards,

    Yousef Shawareb

  • Ivan (Vanya) Kashperuk Profile Picture
    on at

    Just make sure to assign a null to the table buffer variable you will insert inside your changecompany statement:

    InventTable itFrom;

    InventTable itTo;

    itFrom = InventTable::Find("OL-1000");

    changeCompany("OTH")

    {

        itTo = null;

        buf2buf(itFrom, itTo);

        itTo.insert();

    }

     

    Note, that I wrote it right here inside the editor, so I am not sure this compiles.

  • Anton Tjiptadi Profile Picture
    2,013 on at

    Hi,

    Thanks for the reply.
    I've found one good example code for this... Thanks for the original author :)

    static void Transfer_Rec(Args _args)
    {
        DictTable         dicttable;
        DictField         dictfield;
        Common            common,common1;
        int               fieldcnt,i;
        fieldId           fieldid;
        UserTable    TempTable,TempTable1; // UserTable is the table, whose data u want to copy

        ;


        while select TempTable
        {
            common = TempTable;
            dicttable = new DictTable(common.TableId);
            changeCompany("tst")
            {
                 TempTable1 = null;
                 common1    = TempTable1;
                 fieldcnt   = dicttable.fieldCnt();
                 for (i = 1; i <= fieldcnt; i++)
                 {

                    fieldid   = dicttable.fieldCnt2Id(i);
                    dictfield = new dictfield(common.TableId,fieldid);
                    if (dictfield.id() == fieldname2id(common.TableId,identifierstr(dataareaid)))
                        continue;
                    else
                        common1.(dictfield.id()) =  common.(dictfield.id());

                 }
              common1.insert();
             }

         }
         print strfmt('done');
         pause;
    }

    Again, Thanks :) 

     

     

  • Ivan (Vanya) Kashperuk Profile Picture
    on at

    Sorry, but this example is not actually good.

    I suggest you use the one I suggested above. It does absolutely the same, but without the tons of redundant code.

  • Rola Halabi Profile Picture
    135 on at

    hi Ivan, 

    how about if i want to import the entire table, not just that one row with the Id? lets say i want to copy the employee table from an AX company to another?

  • Ivan (Vanya) Kashperuk Profile Picture
    on at
    If you are on an AX installation which has the crosscompany keyword, you can do insert_recordset emplTable (EmplId, ....) select crosscompany : YourCompanyContainer EmplId, ... from emplTableSelect; If not - row by row with changeCompany()
  • Anton Tjiptadi Profile Picture
    2,013 on at

    Hi Ivan,

    YOU'RE THE MAN !!!!!!!!!!!

    I've tried using your method and it works. Thanks a lot.

    regards,

  • user5555 Profile Picture
    7,437 on at

    Hi,

    I have item X and would like to create item Y which is similar except of the item no (SKU). Does anybody have a piece of sample code to share? I think a copy function with a modal dialog for the new name of a GUID would be great.

    J.

     

  • Ivan (Vanya) Kashperuk Profile Picture
    on at
    Do you really need to code? What about the standard record template? I think that's exactly or almost exactly what you need
  • user5555 Profile Picture
    7,437 on at

    Hi,

    It does not copy the dimensions (in our case: sizes) and the item coverage. If I could change this, that would be great.

    J.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans