Wednesday, August 22, 2018

Table Buffer2Buffer by comparing source and target table fields in Dynamics AX


Public static void buffer2buffer(Common _source, Common _target)
    {
        TableScope scope = TableScope::CurrentTableOnly;
        DictTable   sourceDictTable = new DictTable(_source.TableId);
        DictTable   targetDictTable = new DictTable(_target.TableId);

        FieldId     sourceFieldId   = sourceDictTable.fieldNext(0, scope);
        FieldId     targetFieldId   = targetDictTable.fieldNext(0, scope);

        Map targetFields = new Map(Types::String, Types::Int64);

        //Adding target table fields in to Map
        while (targetFieldId && ! isSysId(targetFieldId))
        {
            targetFields.insert(targetDictTable.fieldName(targetFieldId), targetFieldId);
            targetFieldId         = targetDictTable.fieldNext(targetFieldId, scope);
        }  
        
       //Retrieving source field map and comparing with target table fields to set field values
        while (sourceFieldId && ! isSysId(sourceFieldId))
        {
            if (targetFields.exists(sourceDictTable.fieldName(sourceFieldId)))
            {
                targetFieldId = targetFields.lookup(sourceDictTable.fieldName(sourceFieldId));
                _target.(targetFieldId)   = _source.(sourceFieldId);
            } 
            sourceFieldId         = sourceDictTable.fieldNext(sourceFieldId, scope);
        } 
    }


No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...