Reset a NumberSequence in AX2012

Today I want to show you a quick and dirty way, to reset a given NumberSequence in AX2012 per X++ code.

Reset NumberSequence:

static void ResetNumSeq(Args _args)
{
NumberSequenceTable numSeqTable;
try
{
ttsbegin;
select forUpdate * from numSeqTable
where numSeqTable.RecId == 22565432450; // RecId from NumberSequenceTable
if (numSeqTable && numSeqTable.selectForUpdate())
{
info(strFmt("Before: %1", numSeqTable.NextRec));
numSeqTable.NextRec = numSeqTable.Lowest;
if (numSeqTable.validateWrite())
numSeqTable.update();
else
throw Exception::Error;
}
else
throw Exception::Error;
ttscommit;
info(strFmt("After: %1", numSeqTable.NextRec));
}
catch (Exception::Error)
{
error("Update failed :/");
}
}
view raw ResetNumSeq hosted with ❤ by GitHub

What happens here, is that we select the number sequence from the NumberSequenceTable and set the NextRec field to the  value from the Lowest field. The NextRec holds the next value of the number sequence, Lowest the lowest value of the sequence.

Result:

In the screenshot below, you can see the NextRec value before the reset and then the value after.

AX2012 Reset NumberSequence

Advertisement

You may also like...