Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Axapta 将表数据从一个对象复制到另一个对象AX 2012_Axapta_Dynamics Ax 2012_Dynamics Ax 2012 R2_Dynamics Ax 2012 R3 - Fatal编程技术网

Axapta 将表数据从一个对象复制到另一个对象AX 2012

Axapta 将表数据从一个对象复制到另一个对象AX 2012,axapta,dynamics-ax-2012,dynamics-ax-2012-r2,dynamics-ax-2012-r3,Axapta,Dynamics Ax 2012,Dynamics Ax 2012 R2,Dynamics Ax 2012 R3,我正在尝试做一项工作,该工作用于将日记账名称从一个实体复制并插入到另一个实体。下面的代码只能处理我硬编码的字段。但我正在尝试做一个代码,这将在将来很有用,也就是说,如果我们向表中添加新的自定义字段。我的代码应该能够复制新添加的自定义字段的数据 static void sa_CopyData(Args _args) { LedgerJournalName tblLedgerJournalNameSource, tblLedgerJournalNameDesination; Nu

我正在尝试做一项工作,该工作用于将日记账名称从一个实体复制并插入到另一个实体。下面的代码只能处理我硬编码的字段。但我正在尝试做一个代码,这将在将来很有用,也就是说,如果我们向表中添加新的自定义字段。我的代码应该能够复制新添加的自定义字段的数据

static void sa_CopyData(Args _args)
{
    LedgerJournalName   tblLedgerJournalNameSource, tblLedgerJournalNameDesination;
    NumberSequenceTable tblNST, tblNSTCopy;
    NumberSequenceScope tblNSS;
    Counter             countIN, countOUT;
    DataAreaId          sourceEntity, destinationEntity;

    sourceEntity    = 'CNUS';
    destinationEntity = 'CNEN';
    //Journal Names creation
    changeCompany(sourceEntity)
    {
        tblLedgerJournalNameSource = null;
        while select * from tblLedgerJournalNameSource
            where tblLedgerJournalNameSource.dataAreaId == sourceEntity
        {
            ++countIN;
            tblNSTcopy = null; tblNST = null; tblNSS = null;

            select * from tblNSTcopy
            where tblNSTCopy.RecId == tblLedgerJournalNameSource.NumberSequenceTable;

            changeCompany(destinationEntity)
            {
                tblNST = null; tblNSS = null; tblLedgerJournalNameDesination = null;

                select * from tblNST
                    join tblNSS
                    where tblNST.NumberSequenceScope == tblNSS.RecId
                    && tblNST.NumberSequence == tblNSTCopy.NumberSequence
                    && tblNSS.DataArea == destinationEntity;

                //Insert only if Journal name is not exists
                if(!(LedgerJournalName::find(tblLedgerJournalNameSource.JournalName)))
                {
                    ttsBegin;
                    tblLedgerJournalNameDesination.initValue();
                    tblLedgerJournalNameDesination.JournalName = tblLedgerJournalNameSource.JournalName;
                    tblLedgerJournalNameDesination.Name = tblLedgerJournalNameSource.Name;
                    tblLedgerJournalNameDesination.JournalType = tblLedgerJournalNameSource.JournalType;
                    tblLedgerJournalNameDesination.ApproveActive = tblLedgerJournalNameSource.ApproveActive;
                    tblLedgerJournalNameDesination.ApproveGroupId = tblLedgerJournalNameSource.ApproveGroupId;
                    tblLedgerJournalNameDesination.NoAutoPost = tblLedgerJournalNameSource.NoAutoPost;
                    tblLedgerJournalNameDesination.WorkflowApproval = tblLedgerJournalNameSource.WorkflowApproval;
                    tblLedgerJournalNameDesination.Configuration = tblLedgerJournalNameSource.Configuration;
                    if (!tblNST.RecId)
                    {
                        info(strFmt('Number Sequence is not updated for %1 > Entity %2', tblLedgerJournalNameDesination.JournalName, destinationEntity));
                    }
                    tblLedgerJournalNameDesination.NumberSequenceTable = tblNST.recid;
                    tblLedgerJournalNameDesination.NewVoucher = tblLedgerJournalNameSource.NewVoucher;
                    tblLedgerJournalNameDesination.BlockUserGroupId = tblLedgerJournalNameSource.BlockUserGroupId;
                    tblLedgerJournalNameDesination.FixedOffsetAccount = tblLedgerJournalNameSource.FixedOffsetAccount;
                    tblLedgerJournalNameDesination.OffsetAccountType = tblLedgerJournalNameSource.OffsetAccountType;
                    tblLedgerJournalNameDesination.OffsetLedgerDimension = tblLedgerJournalNameSource.OffsetLedgerDimension;
                    tblLedgerJournalNameDesination.LedgerJournalInclTax = tblLedgerJournalNameSource.LedgerJournalInclTax;
                    tblLedgerJournalNameDesination.insert();
                    ttsCommit;
                    ++countOUT;
                }
            }
        }
    }

    info(strFmt('Journal Names Creation > Read: %1, Inserted: %2', countIN, countOUT));
}
如果您有任何建议,请告诉我。

使用
buf2buf(from,to)

它不会执行插入操作,因此在执行插入操作之前,可以修改目标中所需的任何字段

您可以执行
tblledgerJournalNameDesiation.data(tblLedgerJournalNameSource)但这也会复制系统字段,而您很可能不需要这些字段


您还可以查看
Global::buf2Buf(from,to)
背后的源代码,并根据需要修改该逻辑。

感谢您的回复。但我不能将实体从“CNUS”更改为“CNEN”。此外,在某些情况下,您可以使用
y.data(x)
将所有字段从x复制到y。我不记得这是否可以用于像这里这样的跨公司场景。@SankarR-是的,你可以。您仍然要更改公司()
。看见