Thursday, September 26, 2013

Recycling number sequence

So far I've seen a few instances where standard AX2012 can't handle continuous number sequence on certain EDT. Purchase order number (PurchId) is one of those affected.
- If you create a new order and then delete it, no numbers added to the status list and the purchId is not recycled.
- If you create a new order using the "Create purchase order" form, and click "cancel" in the form. The number is now added to the status list. Then the number can be freed by the clean-up action.

In these cases, one option is to add code to free the number ourselves. Using PurchId as an example, add the code below at purchTableType.delete() method will add the purchId to the status list of the number sequence.
   
VersioningPurchaseOrder::newPurchaseOrder(purchTable).delete();
purchTable.doDelete();

// Add the line below to free up the purchId
NumberSeq::releaseNumber(PurchParameters::numRefPurchId().NumberSequenceId, purchTable.PurchId); 

sourceDocumentHeader.delete();
            
One thing to consider, though, is that we have to be sure the Id we are freeing are no longer used/referenced in other tables in AX. Other than that, it should be pretty straight forward.

Please leave a comment if you think of other things to consider when making this change. =D

Cheers.

This posting is provided "AS IS" with no warranties, and confers no rights.

1 comment:

  1. Thank you so much, help me a lot.

    ReplyDelete