Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

New number sequence by code

(0) ShareShare
ReportReport
Posted on by 592
Hi guys,
 
I'm using x++ to create Sales Order and using this code to fetch the number sequence :
 numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId()); numberSeq.used();  salesTable.SalesId = numberSeq.num();
Question is, when this number sequence is set to be /Continuous/, we often (not always) receive error saying the Sales Id is already exist, which we're not sure why system get an old numbers, which in fact it is true that the number already used. So, if I want to /ignore/ the continuous, can I do that and how ?
 
So my code will always get the latest number sequence and system no need to check what's in the cached or anything, just the next number.
 
Thanks.
 
 
 
 
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,979 Super User 2025 Season 1 on at
    New number sequence by code
    Hi Voltes,
     
    In coding, you can't and should not bypass the Continuous setting. Have you checked if the numbers in the status list come from your batch job or from manual entry or another process?
  • Voltes Profile Picture
    Voltes 592 on at
    New number sequence by code
    Thanks Andre,
     
    The process of creating Sales Order is part of a batch job processes. And it is possible to process many records at 1 batch job. Could it be this is the cause of "false" number getting retrieved, as you're mentioned probably in the middle of process we're hit a system error. Although I did put used() directly after NewGetNum() as on my given code in my thread.
     
    Anyway, can in code we "ignore" this "continuous" so that this only will reflected if the SO is created manual, but if it is from code, it will always get the last number ?
    Or should I always clear (delete) all records in status list first, provided in my business scenario actually create manual is hardly happened. But we just "still" want to make this "continuous" on (for manual create only). I know this is doesn't sound make sense. I just want to know whether this is do-able in coding.
     
    Thanks again.
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,979 Super User 2025 Season 1 on at
    New number sequence by code
    Hi Voltes,
     
    In case you don't want to reuse deleted numbers, then disable the Continuous option on the number sequence itself. This is the easiest solution.
     
    I don't know if your tasks is the only way how you would create orders in your environment. On the NumberSeq class, there is an option to enable a  'makeDecisionLater'. If this is enabled, it will put the number in a status list if it is set to be continuous until you use a method 'used()'. Then it will delete the record from the number sequence status list. In case it did take a number with makeDecisionLater, but the used() method was not called, the status list is not cleaned. After a number sequence cleanup, it will think to set the status to free, having the number available to be reused. In case the order was created without having the status list cleaned, you can expect the issue for getting duplicate numbers.
     
    Check which processes are creating the orders and when records will not be cleaned in the status list. You can review the current list on a form that can be opened from the number sequence itself. In case you missed calling the used() method, ensure you will add it.
     
    Note that in case the number was retrieved and in between there is a system failure, it might not be able to call the used() method. As an exception, it will then have the status list with the number. Depending on your transaction scopes, a sales order was created or not.
  • Voltes Profile Picture
    Voltes 592 on at
    New number sequence by code
    Hi both,
     
    Thanks. In reply to Mohit's, I found it quite weird as of why we need to "manually" check the number retrieved from function newGetNum() exist already ? Is it necessarry and why NewGetNum() returned an already used numbers ? 
     
    However, I will try to add first, for me to fix this issue faster.
  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    New number sequence by code
    Hi Voltes,
     
    Continuous number sequence may not skip any numbers. It will reuse them anytime.
    You can go for non-continuous number sequence - In non-continuous number sequence number will be used sequentially but it will skip numbers. If you use non-continuous number sequence, you can enable the Pre allocation feature, When you specify a quantity of numbers to preallocate, the system selects those numbers and stores them in memory. New numbers are requested from the database only after the preallocated quantity has been used. This will improve performance.
    For your scenario you can change it to Non continuous which will get numbers sequentially but skipped numbers will not be used anywhere. If you change it to Non continuous number sequence and you are planning to again come back to Continuous, then it's not recommended to change this as it may cause problems.
     
    Thanks,
    Girish S.
  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    New number sequence by code
    Hi, Continuous number sequence does not skip numbers which means if you have created 3 sales orders with SalesId S001, S002, S003 and later deleted S002, system will not create S004 but will create with S002 as its available again. That's why numbers may not be used sequenctially.
     
    In your code, you can add line to find if number retrieved already exists, if not use that number in SalesId, else execute your code again to find next number.
     
     

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

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans