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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to use, unused number sequence after cancel button is clicked

(1) ShareShare
ReportReport
Posted on by 668

Hi Folks,

I have generated a continuous number sequence for my custom EDT "XXX" through code. Everything works fine. But I wanna know is there any way we could get the previously generated number sequence if it's not written to database. 

Scenario: 

Step 1: Created a new record in my form which generates a number sequence XXX0001 for my custom EDT and saved the record

Step 2: On creating another new record and this time a number sequence of XXX0002 gets generated but this time "Cancel" button is clicked and XXX0002 is not written to the database as records doesn't save the record.

Step 3: After creating new record, now the system generates the number sequence XXX0003 even though XXX0002 is unused for my record. 

Goal: I want to find a way to generate XXX0002 in third step instead of XXX0003. 

Can anyone please suggest? Appreciate your time. 

I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    300,904 Super User 2025 Season 2 on at

    Hi D365FO Avatar,

    You need to use the functions available on the NumberSeq class.

    When retrieving a new number, you can set a parameter for _makeDecisionLater to true.

    At that moment, when retrieving the number sequence on your form it will add the new number to the number sequence status list.

    When a user will save the record, then call the method 'used()'. When he cancels, then call the method 'abort()'.

    The method 'used()' will delete the record in the status list. The 'abort()' function will keep the record but will set it with a status free.

    When there is a free number in the status list, it will pick that number before getting a new number from the Next field on the number sequence. Also have a look at standard coding using these methods.

  • D365FO Avatar Profile Picture
    668 on at

    Hi Andre,

    I have implemented as you suggested in below code, but still it is not working as in abort() method it is going under first condition where active variable is false.

     

    [ExtensionOf(formstr(XXX))]
    final class XXXFrm_Extension
    {
        public       NumberSeq              numberSeq;
        Public       XXX                    projIdnew;
    
        void init()
        {        
            if (! numberSeq)
            {
                ttsbegin;
                numberSeq  = NumberSeq::newGetNum(NumberSequenceReference::findByDatatypeAndScope(extendedTypeNum(XXX)), true);
                ProjIdnew = numberSeq.num();
                numberSeq.used();
                ttscommit;
    
            }
           
            next init();
        }
    
        /// 
        ///
        /// 
        public void closeCancel()
        {
    
            ttsbegin;
            if (numberSeq)
            {
                numberSeq.abort();
            }
            
            next closeCancel();
    
            ttscommit;
        }
    
    }

    pastedimage1672743084588v1.png

  • Verified answer
    André Arnaud de Calavon Profile Picture
    300,904 Super User 2025 Season 2 on at

    Hi D365FO Avatar,

    The "numberSeq.used();" statement should not be used in the init() method. You must implement this on the closeOK() method.

  • D365FO Avatar Profile Picture
    668 on at

    Thanks Andre,

    I have took the help of AssetTable form and tried to do the same way. It worked on three methods first on Modified method, write() of datasource and used closed() of form.

    But here, I tried to re -use the number sequence after the project is deleted.

    I thought to use the delete() of ProjTable, but than I realized that in ProjTable, I'll not be able to use the number sequence buffer.

    So could you please confirm, can I do this while deletion of Project.

  • André Arnaud de Calavon Profile Picture
    300,904 Super User 2025 Season 2 on at

    Hi d365fo-avatar,

    I'm getting a bit confused. You started the question with a custom EDT, but now you are asking about the ProjTable?

    I haven't checked all the coding related to number sequences on the ProjTable. Not sure if it is supported by Microsoft to put the number from a deleted project back in the status list. There is some actual coding for taking care of this on ledger journal lines. When you delete a journal line, it will create a record for that number in the status list.

  • Tracy wang Profile Picture
    113 on at

    can you see your topic  of  question?but why  your answer  have  no   connection with your question?

  • Suggested answer
    CU14050725-0 Profile Picture
    2 on at
      public void delete()
        {
           
            NumberSequenceTable numSeqTable;

            Car_ID carId      = this.CarId;
            numSeqTable       = NumberSequenceTable::find(HB_Car_ID_NumSeq::numRefCarId().NumberSequenceId);
            super();
            if (numSeqTable.Continuous)
            {
                NumberSeq::releaseNumber(HB_Car_ID_NumSeq::numRefCarId().NumberSequenceId, carId);
            }
            else
            {
                if (NumberSeq::numInsertFormat(numSeqTable.NextRec - 1, numSeqTable.Format) == carId)
                {
                    ttsbegin;
                    numSeqTable = NumberSequenceTable::find(numSeqTable.NumberSequenceScope, true);
                    numSeqTable.NextRec--;
                    numSeqTable.doUpdate();
                    ttscommit;
                }
            }
        }
    Override this method to your table and add method in your number sequence 
    public static NumberSequenceReference numRefCarId()
        {
            // Find and return the number sequence reference for Car_ID extended data type
            return NumberSeqReference::findReference(extendedTypeNum(Car_ID));
        }

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

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
Martin Dráb Profile Picture

Martin Dráb 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans