Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

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

(1) ShareShare
ReportReport
Posted on by 457

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. 

  • Suggested answer
    CU14050725-0 Profile Picture
    CU14050725-0 2 on at
    How to use, unused number sequence after cancel button is clicked
      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));
        }
  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: How to use, unused number sequence after cancel button is clicked

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

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,031 Super User 2025 Season 1 on at
    RE: How to use, unused number sequence after cancel button is clicked

    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.

  • D365FO Avatar Profile Picture
    D365FO Avatar 457 on at
    RE: How to use, unused number sequence after cancel button is clicked

    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.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,031 Super User 2025 Season 1 on at
    RE: How to use, unused number sequence after cancel button is clicked

    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
    D365FO Avatar 457 on at
    RE: How to use, unused number sequence after cancel button is clicked

    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

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,031 Super User 2025 Season 1 on at
    RE: How to use, unused number sequence after cancel button is clicked

    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.

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…

Vahid Ghafarpour – Community Spotlight

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

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans