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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

how to create auto increment(value) field in table, and share the code?

(0) ShareShare
ReportReport
Posted on by 2,172

In my project i am using the field called AcademicID, which should auto increment the value(integer) for each input given. pls hep me thanks in advance

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    AX typically uses the Number Sequence Framework for these things, although you can implement an auto-increment field by your own code, if you want.

  • Anand AX Profile Picture
    2,172 on at

    Dear Mr.Martin, Thanks for your response, can u pls share the code or explain about how to use  Number Sequence Framework?, because am new to IT and Ax.

  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    Please look at the link in my previous reply.

  • Verified answer
    Faisal Fareed Profile Picture
    10,796 User Group Leader on at

    Hi Anand, Please have a look on this link which explains step by step how to use number sequence in AX 2012.

    http://daxture.blogspot.co.nz/2014/09/number-sequence-framework-step-by-step.html

    Mark it as an answer if it helps you.

  • Verified answer
    Community Member Profile Picture
    on at

    as you field AcademicID is a integer field so

    I suggest you should override initvalue() method on the table to write logic to increment the value.

    simple logic would be

    count the number of record in table and

    assign value to AcademicID field by incrementing the total value by 1

    Please verify if this helps you.

  • Anand AX Profile Picture
    2,172 on at

    Dear Mr.Faisal The link u provided is really very helpful, Thanks a lot

  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    Doing it in initValue() would likely lead to duplicate values (or DuplicateKeyException if there is a unique index), because before the record gets written to dataabase, initValue() may be called for other records and they would all get the same value.

  • Community Member Profile Picture
    on at

    Hi ,

    I need suggestion,

    working on Ax 2009,

    I have a field say F1 and I am using it in a for loop, now my requirement is :

    till the loop runs the F1 value should Increment by 1, say field value F1= A100, if loop run for 5 time, the the field value should be increment like this A101,A102..A105. 

  • UmesH@ Profile Picture
    810 on at

    It's Easy To Create in Number Sequence in DataSource.

    Create DataSource Create Method.

    public void create(boolean _append = false)
    {
        int max1;
        A_Marks _Marks;
        str 60 Value;
        str 60 _newCode;
        ;
        //breakpoint;
        super(_append);
        select firstOnly ID from _Marks order by RecId desc;// query to find last number
        if(!_Marks.ID)// When table is blank
        {
            _newCode='MT_'+ strRFix(int2str(1),3, "0");//Assigne value to table field
            DSMarks.ID = _newCode;//Assigne value to table field
        }
        else
        {
            max1=str2int(subStr(_Marks.ID,4,3))+1;// When table is not blank, add 1
            DSMarks.ID ='MT_'+ strRFix(int2str(max1),3, "0");//Assigne value to table field
        }// if Close
    
    }


    Might be Help this Code.

    Thanks.

  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    It has the same problem as doing it in initValue(). Also the sorting by RecId is wrong - the record with highest RecId doesn't have to have the highest 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans