Dynamics User Group
Since 1995 - The Microsoft Dynamics Online User Community

Table copy between company's

rated by 0 users
This post has 12 Replies | 4 Followers

Not Ranked
Male
Posts 22
Points 440
Member since 08-09-2005
msz_ Posted: 10-19-2007 11:21

 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 

Top 10 Contributor
Male
Posts 3,440
Points 106,041
Member since 10-01-1995
DynamicsNAVMVP
Moderator
SystemAdministrator

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

Best regards,
Erik P. Ernst - webmaster at dynamicsuser.net

DynamicsUser.net Admin's Blog

Not Ranked
Male
Posts 22
Points 440
Member since 08-09-2005

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 )


  • | Post Points: 50
Top 10 Contributor
Male
Posts 3,440
Points 106,041
Member since 10-01-1995
DynamicsNAVMVP
Moderator
SystemAdministrator

Oh I'm sorry I didn't see this was about Axapta! I only know Navision! Surprise

Best regards,
Erik P. Ernst - webmaster at dynamicsuser.net

DynamicsUser.net Admin's Blog

  • | Post Points: 5
Top 25 Contributor
Male
Posts 544
Points 4,397
Member since 01-21-2003
DynamicsAXMVP
Moderator
Hello, There are plenty of examples in Ax as well as some example in Developers hand book. Hope this helps,
Harish Mohanbabu Long way to go before I sleep .. View Harish Mohanbabu's profile on LinkedIn
  • Filed under:
  • | Post Points: 5
Top 75 Contributor
Male
Posts 247
Points 2,400
Member since 03-23-2005
Moderator

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

{

//processing

}

2. 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.

3. 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

Kashperuk Ivan (Vanya)
My blog
Dynamics AX links
Top 500 Contributor
Male
Posts 76
Points 1,085
Member since 10-04-2007

Hi,

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.Yes

Manish
Not Ranked
Male
Posts 22
Points 440
Member since 08-09-2005

 Thank You for help. I was all I needed.

  • | Post Points: 5
Not Ranked
Male
Posts 22
Points 440
Member since 08-09-2005

 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?

Top 500 Contributor
Male
Posts 76
Points 1,085
Member since 10-04-2007
Hi, I dont hav any idea abt that. If I can see the code, may be I am able to say something...
Manish
  • | Post Points: 20
Not Ranked
Male
Posts 22
Points 440
Member since 08-09-2005

 Here it's the code.... Smile

.....

 dictTable = new DictTable(tabId);

    ril = new recordinsertlist(tabId);

    myTable = dictTable.makeRecord();

    while select mytable
    {
    ril.add(mytable);

    } 


    changecompany('tst')
    {
    ttsbegin;
    ril.insertDatabase();
    ttscommit;
    }
   
 

Not Ranked
Male
Posts 7
Points 65
Member since 07-04-2007

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.

 

 

Top 500 Contributor
Male
Posts 76
Points 1,085
Member since 10-04-2007

Hi,

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);
        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;
}
Hope, this will work for u...Yes

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

bye

Manish
Page 1 of 1 (13 items) | RSS


Copyright Dynamics User Group, 1995-2009, all rights reserved. The Dynamics User Group is not affiliated with Microsoft Corporation.