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

Notifications

Announcements

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
    238,032 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
    238,032 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
    238,032 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
    238,032 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

News and Announcements

Season of Giving Solutions is Here!

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Nakul Profile Picture

Nakul 2

#1
user5555 Profile Picture

user5555 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans