Monday, October 4, 2021

How to roll back a number sequence in D365FO

 Today we discuss, how to roll back number sequence if any validation failed in D365FO.

If number sequence is creating without using NumberSeq class. we can use 

ttsbegin;

// our logic

ttscommit;

If any validation failed the system roll back everything.


If we creating number sequence using NumberSeq class by abort() method we can recover that number. This only works if in the same transaction scope as NumberSeq and if the number sequence is continuous. if not, both calls are no-operations.


        NumberSeq numSeq = NumberSeq::newGetNum(Parameters::numRefMyId(), true);

// NumberSeq numSeq = NumberSeq::newGetNumFromId(Table.AutoNumberSequenceTable, true); MyTable myTable; ; try { myTable.clear(); myTable.myId = numSeq.num(); if (myTable.validateWrite()) { myTable.insert(); numSeq .used(); } } catch (Exception::Error) { numSeq .abort(); }


Keep daxing!!

No comments:

Post a Comment