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:

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab...