I'm trying to do a Job which used to Copy and insert Journal Names from one entity to another entity. Below code able to handle only fields only I hardcoded. But I'm trying to do a code which will be useful in future i.e if we add new custom field to the table. My code should able to copy data of that newly custom field added.
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));
}
Please let me know if you have any suggestions.