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 :
Small and medium business | Business Central, N...
Answered

How a Code datatype field can be auto-incremented

(0) ShareShare
ReportReport
Posted on by 436

I want to ask that in the picture below, there is a field ("Document No.") whose datatype is Code[20] but still the field is auto-incremented whenever a new line is created. Like in the above picture, for the first line "Document No." was G0003 and automatically when I initialized the new line the "Document No." becomes G0004. How can a Code datatype be auto-incremented? And how can I do that when I have to enter it by passing some action?

pastedimage1672148284198v1.png

  • Suggested answer
    Mohana Yadav Profile Picture
    61,260 Super User 2026 Season 2 on at

    You can find the function in Table 81 - IncrementDocumentNo

  • Suggested answer
    DAnny3211 Profile Picture
    11,427 Super User 2026 Season 1 on at

    hi

    use this function in codeunit 396

    pastedimage1672153507150v1.png

    DAniele

  • Suggested answer
    pankaj.k Profile Picture
    1,020 on at

    Hi Muhammad

    "Document No."  is  Data Type=Code field Increment Automatically with the help of GetNextNo Function this function is available on Table No 81.

    this Function use NoSeries  that is Assign on "Payment Journal Batch" Page.

    8510.Capture.PNG

    How to create No. Series : https://learn.microsoft.com/en-us/dynamics365/business-central/ui-create-number-series

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    If you are writing AL code and do not have any no. series connected to your field you can use the incstr function as documented here:

    learn.microsoft.com/.../text-incstr-method

  • Suggested answer
    YUN ZHU Profile Picture
    104,090 Super User 2026 Season 2 on at

    Hi, Just to add a simple example.

    How to use the standard No. Series on custom data in Dynamics 365 Business Central (Automatic Number Series)

    https://yzhums.com/2278/

    Hope this can give you some new hints too.

    Thanks.

    ZHU

  • Muhammad Anas Naeemi Profile Picture
    436 on at

    Thanks everyone, but IncStr() worked for me.

  • Suggested answer
    Mohana Yadav Profile Picture
    61,260 Super User 2026 Season 2 on at
    IncrementDocumentNo function will be doing the same so why to reinvent the wheel?

    pastedimage1672211603267v1.png

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at
    [quote user="Mohana Yadav"]
    IncrementDocumentNo function will be doing the same so why to reinvent the wheel?

    pastedimage1672211603267v1.png

    [/quote]

    There can be many situation where you want to increment a code field or a text string without connecting a no, series to it. And in those cases incstr is the correct way to handle it. 

    There can also be situations where using the NoSeriesManagement codeunit causes locking in your system, then you need and alternative way to increase your code field. 

    So "one wheel" does not always fit all scenarios. 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 665 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 418 Super User 2026 Season 2

#3
Teagen Boll Profile Picture

Teagen Boll 280 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans