Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

How a Code datatype field can be auto-incremented

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

Categories:
  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,744 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. 

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 58,878 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 70,059 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,744 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
    pankaj.k Profile Picture
    pankaj.k 960 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,217 Moderator 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 58,878 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

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,556 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,625 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans