Saturday, 25 April 2015

Copy Data From One Table To Another Table By Using buf2buf- Ax 2012

Hello Guys...!

Some times we get requirement like , we have to copy data from one table to other table .

For that we use buf2buf()  Global method. This method we can use if our second table fields Id's are same as First table field Id's.

If not then we need to do some changes in buf2buf() method

Example :

-> Here i duplicated "InventTable" and named "CopyInventTable"
->I'm copying data from InventTable to CopyInventTable by using Buf2Buf method

Step 1:

Go to Class-> Global-> buf2buf() method and paste below code

static void buf2buf(Common  _from, Common  _to)
    DictTable   dictTableFrom   = new DictTable(_from.TableId);
    DictTable   dictTableTo     = new DictTable(_to.TableId);
    DictField   dictFieldFrom;
    FieldId     fieldIdFrom     = dictTableFrom.fieldNext(0);
    FieldId     fieldIdTo

    while (fieldIdFrom && ! isSysId(fieldIdFrom))
        dictFieldFrom   = new DictField(_from.TableId, fieldIdFrom);

            fieldIdTo = dictTableTo.fieldName2Id(;

                _to.(fieldIdTo) = _from.(fieldIdFrom);

        fieldIdFrom = dictTableFrom.fieldNext(fieldIdFrom);

Step 2 :

Paste the below code in AOT -> Jobs and new Job

static void CopyData(Args _args)
    InventTable inventTable;
    CopyInventTable copyInventTable ;
    while select inventTable
         buf2Buf(inventTable ,copyInventTable );
         copyInventTable .insert();

That's It.

@Rahul Talasila

1 comment:

Foreign currency revaluation currencies not showing in drop down in dynamics 365 finance & Operations 8.0

In the previous versions you can see all currency codes in the currency drop down, but Dynamics 365 finance and operations 8.0 you don'...