Thursday 3 January 2013

Copying data of one table to another table across the company in AX

//Copying data of one table to another table across the company in AX2009
static void CopyDataFromOneTableToAnother(Args _args)
{
    TableA                  tableA;
    TableB                  tableB;
    DataArea                dataArea;
  
    ;

  while select dataArea
     {

        changeCompany(dataArea.id)
        {
            tableA= null;
            tableB= null;
            while select tableA
            {
              tableB.CustAccount        = tableA.CustAccount;
              tableB.ItemCode           = tableA.ItemCode;
              tableB.insert();
            }
        }
     }

      info(strfmt("Mission Accomplished"));

}

3 comments:

  1. 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();

    }

    ReplyDelete
  2. newTable.data(originalTable)

    I suspect there is a performance benefit to the .data() method as it is more commonly used in standard AX.

    ReplyDelete
  3. http://dynamicsuser.net/forums/p/20394/93643.aspx

    ReplyDelete