Sunday, December 8, 2013

Code to copy data from one table to another even though the tables are different provided the field names are same. in Ax2012



public void copyData(Common _from, Common _to)
{
    DictTable   dictTable   = new DictTable(_from.TableId);
    FieldId     fromFieldId = dictTable.fieldNext(0);
    fieldId     toFIeldid;
    DictField   dictField;

    while (fromFieldId)
    {
         If(! isSysId(fromFieldId))
         {
                 dictField       = new DictField(dictTable.id(), fromFieldId);
        toFIeldid       = fieldName2id(_to.TableId, fieldId2name(_from.TableId, fromFieldId));
        if (toFIeldid)
        {
            _to.(toFIeldid) = _from.(fromFieldId);
        }
        }       
        fromFieldId = dictTable.fieldNext(fromFieldId);
    }

}

1 comment:

  1. Nice one but can you please let me know why you have the below statement

    dictField = new DictField(dictTable.id(), fromFieldId);

    ReplyDelete