web
You’re offline. This is a read only version of the page.
close
Skip to main content
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 390

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

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    60,977 Super User 2025 Season 2 on at
    RE: How a Code datatype field can be auto-incremented

    You can find the function in Table 81 - IncrementDocumentNo

  • Suggested answer
    DAnny3211 Profile Picture
    11,389 on at
    RE: How a Code datatype field can be auto-incremented

    hi

    use this function in codeunit 396

    pastedimage1672153507150v1.png

    DAniele

  • Suggested answer
    pankaj.k Profile Picture
    994 on at
    RE: How a Code datatype field can be auto-incremented

    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
    Inge M. Bruvik Profile Picture
    1,045 Moderator on at
    RE: How a Code datatype field can be auto-incremented

    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
    93,438 Super User 2025 Season 2 on at
    RE: How a Code datatype field can be auto-incremented

    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
    390 on at
    RE: How a Code datatype field can be auto-incremented

    Thanks everyone, but IncStr() worked for me.

  • Suggested answer
    Mohana Yadav Profile Picture
    60,977 Super User 2025 Season 2 on at
    RE: How a Code datatype field can be auto-incremented
    IncrementDocumentNo function will be doing the same so why to reinvent the wheel?

    pastedimage1672211603267v1.png

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,045 Moderator on at
    RE: How a Code datatype field can be auto-incremented
    [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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,085

#2
YUN ZHU Profile Picture

YUN ZHU 1,810 Super User 2025 Season 2

#3
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 1,788

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans