Friday, November 21, 2014

Global::buf2buf() doesn’t work correctly when used with inherited tables.

Hi Friends,

While working on my current project,I faced a issue with the Microsoft Standard Global function.

I have a requirement to copy data of a table.But it is intercompany process.So I can't use the data method.
As Data method copy the sys fields also but in Buf2 Buf it just copy the data fields,not the sys fields.
So decide to use buf2buf.But in my scenario it doesn't work due to table inheritance.

derived table data get copy but not the base table data.

base table data get copy but not the derived table data.

 I found the Solution in Ax2012 R3.
 Here scope is defined,So you have to pass additional the scope as parameter.
If you are copying derived table data ,then you have to pass baseTable as scope.
If you are copying base table data ,then you have to pass derived as scope.

static void buf2Buf(
    Common  _from,
    Common  _to,
    TableScope _scope = TableScope::CurrentTableOnly
    DictTable   dictTable = new DictTable(_from.TableId);
    FieldId     fieldId   = dictTable.fieldNext(0, _scope);
    while (fieldId && ! isSysId(fieldId))
        _to.(fieldId)   = _from.(fieldId);
        fieldId         = dictTable.fieldNext(fieldId, _scope);

No comments:

Post a Comment