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:

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...