Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

How a Code datatype field can be auto-incremented

(0) ShareShare
ReportReport
Posted on by 382

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
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 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. 

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,194 Super User 2024 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

  • RE: How a Code datatype field can be auto-incremented

    Thanks everyone, but IncStr() worked for me.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 74,036 Super User 2024 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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 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
    pankaj.k Profile Picture
    pankaj.k 962 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
    DAnny3211 Profile Picture
    DAnny3211 9,272 Super User 2024 Season 1 on at
    RE: How a Code datatype field can be auto-incremented

    hi

    use this function in codeunit 396

    pastedimage1672153507150v1.png

    DAniele

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,194 Super User 2024 Season 2 on at
    RE: How a Code datatype field can be auto-incremented

    You can find the function in Table 81 - IncrementDocumentNo

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

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans