Friday, 13 September 2019

D365 F&O X++ code to copy data form one table two other table with similar fields using SysdictTable

Today we will see a code, which is useful to copy data from one table to a similar table and let's say you have many fields.



public static Common copyFromToTable(Common _commonFrom, Common _commonTo)
    {
        SysDictTable    dictTable = new SysDictTable(_commonTo.TableId);
        SysDictField    dictField;
        FieldId         fieldId = dictTable.fieldNext(0);
       
        while (fieldId)
        {
            dictField = dictTable.fieldObject(fieldId);

            if (dictField.isSql() && !dictField.isSystem())
            {
                FieldName fieldName = dictField.name();
                FieldId fieldIdFrom = fieldName2Id(_commonFrom.TableId, fieldName);

                if (fieldIdFrom)
                {
                    _commonTo.(dictField.id()) = _commonFrom.(fieldIdFrom);
                }
            }

            fieldId = dictTable.fieldNext(fieldId);
        }

        return _commonTo;
    }

No comments:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...