Table copy between company's

Hi all,

Have you any idea about copy tables between company’s - i would like to choose the table ,source and destination company -it’s simple.

The problem is in the point of make the table buffor - dynamically.

Maybe I should go another way??

Thanks for help

Are you familiar with the CHANGECOMPANY function? This would be able to help you create what you ask for.

I know about it.

But changecompany (and recordsortedlist) function i will use but first i should pick a table to copy. Then how make the table buffer when i don’t know what table will by selected (it’s hard to explain…)

for example:

static void Job34(int NUM)
CustTable ct; << it simple we know that this table (CustTable) we want to buffer, but in my case i don’t know what table will come…

tableNum(NUM) ct; <<< maybe something like that ???

I looking for this becouse then i can make a form and user will can select proper table company >> then copy data form table1-company1 to table1-company2 >> without export - import data (it’s solution too, but too slow )

Oh I’m sorry I didn’t see this was about Axapta! I only know Navision! [:O]

Hello, There are plenty of examples in Ax as well as some example in Developers hand book. Hope this helps,

Well, basically you need to know 3 things.

  1. All tables are “extending” from Common,

so you can declare a variable of type Common myTable; and any record of any table will be able to fit in it.

and later use it as if it was the specific table you need

while select myTable




  1. There is a class DictTable, which has a method “makeRecord”.

DictTable dictTable = new DictTable(NUM); //NUM - is the ID of the table

myTable = dictTable.makeRecord(); //this assigns a buffer of your table to the common record buffer.

  1. There is a Global method buf2buf(), which you can use to copy all the fields of one record to another record of same table.

That’s it.

Hope it helps


Ivan is right.

U can create a job for that.

In that, use changeCompany(), take common object and pass the table that the user selects, to the job.

Use DictTable and DictField to pass values from one object to another.

May b it will help u.If u need, I can send u the code for that.[Y]

Thank You for help. I was all I needed.

One little thing…

You know why, when I load a recordinsertlist (recordsorted too) and next I change company then ONLY FIRST record from list go to the table in new company. All rest go to the “old” company. Why all records from list don’t save in table after changecompany ?

Have You any idea?

Hi, I dont hav any idea abt that. If I can see the code, may be I am able to say something…

Here it’s the code… [:)]

dictTable = new DictTable(tabId);

ril = new recordinsertlist(tabId);

myTable = dictTable.makeRecord();

while select mytable



We need to be careful to one thing with insertDatabase. RecordInsertList does not insert record in table only when execution is now at line ril.insertDatabase(). Axapta insert records in the list when he have the time to do it. One thing is sure, insert of all records in list will be finish at line InsertDatabase. So records can be inserted anywhere in your code between the .add() method and the insertDatabase() method.

In your example, probably Axapta have already inserted in database most of your records in the list when changeCompany(‘tst’) occured and after, the last records with new company is inserted.

Hope this help.


I use a simple job for that.I transfer all data from one object to another of same type, except field “DataAreaId”.

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);
TempTable1 = null;
common1 = TempTable1;
fieldcnt = dicttable.fieldCnt();
for (i = 1; i <= fieldcnt; i++)

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


print strfmt(‘done’);
Hope, this will work for u…[Y]

If there is any scope of modification, pls let me know…


Try using Table Defination Group.

Administration ->Periodic-> Data Export/Import

This is a simple but powerful feature in AX. Firs Export Data from one company and then import data to another company. Very Flexible and easy


I can make a form and user will can select proper table and company >> then copy data to other company in selected table >>>But table is not static >> I want to select table in List.

I read Manish Saxena blog.

Here I write my code…

dictTable1 = new DictTable(table_id);

c1 = dictTable1.makeRecord();

while select c1

dictTable3 = new DictTable(table_id);
c2 = null;
for (i = 1; i <= dictTable3.fieldCnt(); i++)

fieldid = dictTable3.fieldCnt2Id(i);
dictfield = new dictfield(table_id,fieldid);
if ( == fieldname2id(table_id,identifierstr(dataareaid)))
c2.( = c1.(;



It’s Give error…

Plz Help me …

Thanks in Advances,

NImisha Patel


Actually i got task where i should able select any table dynamically by the end user(giving end user a dialogbox to enter the table name) and the select statement should be able to select that particular Tablename which have been entered by enduser.

Please give me sample code…please…