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

Number sequence based on enum value on the form

(0) ShareShare
ReportReport
Posted on by 578

Hi Experts,

I have a requirement that I need to to generate different number sequence for a field based on the selection of  an enum element in the form. example if the user selects enum A the number sequence should be A1,A2,etc. if its B it should be B1,B2, etc. From other posts I understand that it is possible in AX, Is there any step by step reference / sample for the same ? 

Thanks in advance 

  • D365  beginner Profile Picture
    578 on at
    RE: Number sequence based on enum value on the form

    Hi Nikolaos,

    Thanks a lot for your comments, I followed the same logic used for fixed assets and it works fine now.

  • Verified answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Number sequence based on enum value on the form

    Did you check how it's implemented in Fixed assets? Perhaps you can follow the same pattern.

    Regardless of that, here's one suggestion. Provide a dialog for creating records, this way you only need to fetch the number sequence once the user has given all data (including the enum value). Prevent the user from changing the enum value on existing records.

    Or, if you don't want to develop a dialog, fetch the number only when the record is saved (insert method in the table, before super() call, fetch it if the field is empty at this point). And then prevent the user from changing the enum on existing records.

    I assume that this number sequence field is used in some table relations. If yes, changing it after the record has been saved would break relations to any related tables.

  • D365  beginner Profile Picture
    578 on at
    RE: Number sequence based on enum value on the form

    Hi Nikolaos,

    Somehow I managed to reach close to the functioning. I have taken Fixed assets number sequence as per asset group for reference. I am able to generate number sequence now based on an enum value (field named category in my case). I have an issue now that, on the form if I select the same enum value again for the same record,  the number sequence keep incrementing. for example if I select the first enum value the sequence should have generated and If I simply re select the same enum the sequence get incremented for the same record. here I am mentioning the modified method on the field category in my form and the init method which brings the sequence number. what can be done to fix it ?

    void modified()

    {

       NumberSeq           CategoryNumberSeq;

       ;

       super();

       if (CategoryNumberSeq);

           CategoryNumberSeq.abort();

        CategoryNumberSeq = MyMainTable.initCategoryNumberSeq();

        if (CategoryNumberSeq )

       {

           MyMainTable.ItemId   = CategoryNumberSeq.num();

       }

       MyMainTable.dataSource().refresh();

    }

    public server NumberSeq initCategoryNumberSeq(ItemCategory _Category)

    {

       MyCategoryTable = MyCategoryTable ::find( _Category? _Category : this.Category);

       NumberSeq            CategoryNumberSeq;

       ;

       if (MyCategoryTable.AutoNumberSequenceTable)

       {

           CategoryNumberSeq = NumberSeq::newGetNumFromId(MyCategoryTable.AutoNumberSequenceTable, true);

       }

       return CategoryNumberSeq;

    }

  • Suggested answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Number sequence based on enum value on the form

    Hi AX Beginner,

    as I mentioned, you can check how the Customer account number sequence per customer group is implemented.

    Basically you need to add somewhere some setup fields, so that you can link each enum value with a specific number sequence. Then, fetch the correct number sequence based on the enum value.

    In the Customer account number sequence it's not linked to an enum value but a customer group, but the principle is exactly the same.

    axcademy.com/.../

  • D365  beginner Profile Picture
    578 on at
    RE: Number sequence based on enum value on the form

    Hi Nokolaos,

    Thanks for your reply.

    Do you have any link for similar implementation? I couldn't find any.

  • Suggested answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Number sequence based on enum value on the form

    Sure, you can do it. You just have to develop such setup that you can define number sequence separately for each enum value. I think that lately Microsoft has added possibility to define customer account number sequence per customer group, so you could check how they implemented that.

    You also need to decide if you will block the user from changing the category after the number has been assigned.

  • D365  beginner Profile Picture
    578 on at
    RE: Number sequence based on enum value on the form

    Hi Mr. ludwig,

    Thanks for your reply.

    I have a customized table and form where I have a field named ProductId which should be a number sequence. I have another field named product category where I will be having different category like A, B,C etc. I have already setup the number sequence for field product id something like prod1, prod2 etc. the requirement is once the user creates an entry and select product category as A the number sequence for record should be A1, next A2 etc. if the category B is selected the sequence should be B1, B2 etc.

    I hope the requirement is clear now.

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Number sequence based on enum value on the form

    Hello AX Beginner,

    What number sequence do you refer to?

    Best regards,

    Ludwig

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,245 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans