Generate New Number Sequence when Copying Journal Name
Rolling out entity (new company) in AX 2012 is more difficult than in 2009. There are some data that can’t be easily copied across. There are many ways of achieving this. But specifically in this article, we’re talking about copying the journal name. And yes, Journal Name can be copied across using the Standard AX Export Import binary file (not Data Import Export Framework).
The only issue with copying the Journal Name using the above method is the number sequence for the voucher series still referred to the originating company. Though it’s still working when you create journal with this name, but the next number sequence used isn't from the entity itself.
In above example, the voucher series is displayed correctly. We will find the anomaly when we perform right-click and view detail function. The company scope will be difference with the current company we working on. This is basically showing the data saved in the AOT as a result of an export import activity.
The script below is to help rectifying the issue by:
- Create the new number sequence if the number sequence doesn’t exist in the company.
- If the number sequence already exists in the company, then re-apply the correct record id in the journal name.
- Ensure that the pattern of the new number sequence is the same with the originating (source) company.
static void TI_JournalNameVoucherNumSeqCreation(Args _args)
{
NumberSequenceTable numSeqTableFrom, numSeqTableTo;
LedgerJournalName journName;
NumberSeqScope numSeqScope;
NumberSequenceReference numSeqRef;
int result;
SysOperationProgress progressBar;
boolean compareScopeWithCompany(RecId _numSeqTable, DataAreaId _dataArea)
{
return NumberSequenceScope::find(NumberSequenceTable::find(_numSeqTable).NumberSequenceScope).DataArea == _dataArea;
}
boolean isSharedNumber(RecId _numSeqTable)
{
return NumberSequenceScope::find(NumberSequenceTable::find(_numSeqTable).NumberSequenceScope).DataArea == "";
}
;
ttsBegin;
progressBar = new SysOperationProgress();
progressBar.setCaption("Creating number sequence for journal Name");
while select forUpdate journName
/*where journName.JournalName == "GJ" ||
journName.JournalName == "AJ" ||
journName.JournalName == "BK" ||
journName.JournalName == "CJ" ||
journName.JournalName == "VI" ||
journName.JournalName == "VP" ||
journName.JournalName == "CR" ||
journName.JournalName == "CWO" ||
journName.JournalName == "FA" ||
journName.JournalName == "FB" ||
journName.JournalName == "FD" ||
journName.JournalName == "FS" ||
journName.JournalName == "IC" ||
journName.JournalName == "SJ" ||
journName.JournalName == "VA" ||
journName.JournalName == "VR"*/ //put the filter if needed
{
if(!journName.NumberSequenceTable)
continue;
//check if the number sequence for voucher series is available for current company or if it's shared
if( !compareScopeWithCompany(journName.RecId, curext()) && !isSharedNumber(journName.NumberSequenceTable) )
{
progressBar.setText(strFmt("Journal Name - %1", journName.JournalName));
numSeqTableFrom = NumberSequenceTable::find(journName.NumberSequenceTable);
//check if number sequence exists
numSeqTableTo = NumberSequenceTable::findByNaturalKey(numSeqTableFrom.NumberSequence, NumberSequenceScope::findByNaturalKey(curext(), 0,0,0).RecId);
if(numSeqTableTo)
{
journName.NumberSequenceTable = numSeqTableTo.RecId;
journName.update();
info(strFmt("Number Sequence %1 already exists, Journal name %2 is reassigned to %1", numSeqTableTo.NumberSequence, journName.JournalName));
continue;
}
numSeqTableTo.initValue();
numSeqTableTo.Format = numSeqTableFrom.Format;
numSeqTableTo.AnnotatedFormat = numSeqTableFrom.AnnotatedFormat;
numSeqTableTo.NumberSequence = numSeqTableFrom.NumberSequence;
numSeqTableTo.Lowest = numSeqTableFrom.Lowest;
numSeqTableTo.Highest = numSeqTableFrom.Highest;
numSeqTableTo.Continuous = numSeqTableFrom.Continuous;
numSeqTableTo.CleanInterval = numSeqTableFrom.CleanInterval;
numSeqTableTo.Txt = strRem(numSeqTableFrom.Txt, NumberSequenceScope::find(numSeqTableFrom.NumberSequenceScope).DataArea) + curext(); //Change the number sequence description here
numSeqTableTo.NumberSequenceScope = NumberSequenceScope::findByNaturalKey(curext(), 0,0,0).RecId;
try
{
numSeqTableTo.insert();
journName.NumberSequenceTable = numSeqTableTo.RecId;
journName.update();
result++;
info(strFmt('created %1', numSeqTableTo.NumberSequence));
}
catch
{
info(strFmt("number sequence for journal name %1 can't be created", journName.JournalName));
}
}
}
ttsCommit;
info(strFmt("%1 records created", result));
}
Comments
Post a Comment