web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Prevent number sequence consumption when deleting draft documents

(1) ShareShare
ReportReport
Posted on by 196

Question

Hello everyone,

I am working on a custom document form in Dynamics 365 Finance & Operations (10.0.x) called CuttingJob.

High-level design:


  • Header table: CuttingJobHeader

  • Line table: CuttingJobLine

  • A Number Sequence is used for CuttingJobNo

  • Document lifecycle is similar to PO / SO (Draft → Confirm)


  •  

Current behavior:


  • CuttingJobNo is generated when a new Header record is created (Draft)

  • If the user deletes the Draft record, the generated number is lost and cannot be reused

  • The number sequence keeps incrementing




  •  
  •  

Observation:

For standard documents like Purchase Order / Sales Order:


  • Continuous number sequence can be enabled

  • Deleting a Draft document does not consume the number


  •  

For this custom document:


  • The number is consumed as soon as it is generated

  • Deleting the Draft record does not return the number


  •  

Questions:


  1. Is this behavior by design for custom tables in D365FO?

  2. What is the recommended best practice to design a custom document number so that it behaves similarly to PO / SO?

    • For example, delaying number assignment until Confirm instead of Draf 

  3. Is using NumberSeq::newGetNumFromCode(..., true) together with abort() considered production-safe for document numbers?

  4. If the requirement is “do not consume the number when a Draft document is deleted”,

    what is the Microsoft-recommended pattern?

    • Assign number at Confirm?

    • Use a specific document framework or pattern? 


    •  

Constraints:


  • No hacks or direct manipulation of number sequence tables

  • Must be safe for production and multi-user scenarios

  • Should align with D365FO framework principles


  •  

Thanks in advance for any guidance or real-world experience.

Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    238,129 Most Valuable Professional on at
    1. Is this behavior by design for custom tables in D365FO?
    It's about what logic you used in the form; it's not about the table.
     
    2. What is the recommended best practice to design a custom document number so that it behaves similarly to PO / SO?
    As always, the implementation should follow your business requirements. Nevertheless I recommend avoiding continuous number sequences whenever possible. Normal sequences performs better, there are fewer things that can go wrong and it's usually not important whether a number wasn't reused.
     
    3. Is using NumberSeq::newGetNumFromCode(..., true) together with abort() considered production-safe for document numbers?
    It is. If use cross-references, you'll find more than a hundred cases in production code from Microsoft.
     
    4. If the requirement is “do not consume the number when a Draft document is deleted”, what is the Microsoft-recommended pattern?
    I don't think that Microsoft has any recommendation for your particular requirement. I would also challenge the requirement itself. If you delete an existing record (regardless of that a status field had a specific value), it doesn't mean that reusing the number is save. There may be references to the number, e.g. in logs, and reusing the same number for another record may be confusing or lead to errors.
    I would ask users to explain what would be the problem for the business if it the number wasn't reused. Maybe someone just wish to have that but it doesn't have a real business justification.
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,452 Super User 2025 Season 2 on at
    Hi Statics 365,

    Despite you can set up continuous number sequences for several documents, it is not always recommended or supported out of the box for releasing numbers.
     
    In case you really want to release the number, you should consider if it is the last added, or what to do in case you have Job 1-100 and want to delete number 21 after e.g. 6 months. Should it really reuse 21 after this period?
     
    For sales orders and purchase orders, there is a creation form that manages the state of the number sequence before someone clicks on 'OK' and the records is actually saved. This is also managing the state of the number sequence.
     
    For the correct support on continuous number sequences, you need to add X++ coding.
     
    In case you are using the coding NumberSeq::newGetNumFromCode(..., true), you should also call a method NumberSeq::used(). Otherwise, the list with active numbers will not be cleaned correctly. This can be used on e.g. a creation form.
     
    To have a number available after deleting a record, you can call a method to release the number: NumberSeqNumberSeq::releaseNumber({Number Sequence Id}, {number to be deleted}).
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 679 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 410 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 292 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans