我正在尝试做一个用于复制日志名称并将其从一个实体插入另一个实体的作业。下面的代码只能处理字段我硬编码。但我正在尝试做一个将来有用的代码,即如果我们在表中添加新的自定义字段。我的代码应该能够复制添加的新自定义字段的数据。
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));
}
如果您有任何建议,请与我们联系。
答案 0 :(得分:1)
使用buf2buf(from, to)
。 https://msdn.microsoft.com/en-us/library/global.buf2buf.aspx
不执行插入操作,因此在执行buf2buf()
之后,您可以在插入之前修改目标中的任何字段。
您可以执行tblLedgerJournalNameDesination.data(tblLedgerJournalNameSource);
,但这也会复制您很可能不想要的系统字段。
您还可以查看Global::buf2Buf(from, to)
背后的源代码,并根据需要修改该逻辑。