Using the New IncStr Overload in Business Central AL


Article content

With recent updates to AL language in Microsoft Dynamics 365 Business Central, developers now have more flexibility when working with strings containing numeric suffixes — thanks to the new overload of the IncStr method.

If you’ve ever had to increment a string with a number at the end (e.g., “INV001” to “INV002”), you’ve probably used IncStr. But until recently, IncStr only allowed an increment of +1.

Let’s explore how the new overload changes that.

🆕 What’s New in IncStr?

Traditionally, IncStr was used like this:

NewString := IncStr('INV001');  // Result: 'INV002'        

Now, with the new overload, you can specify how much to increment by:

NewString := IncStr('INV001', 5);  // Result: 'INV006'        

✅ Syntax:

IncStr(Value: String, IncrementBy: Integer): String
        

This enhancement is particularly useful in scenarios like:

  • Batch processing: Skipping ranges (e.g., test IDs, invoice numbers)
  • Custom logic: Implementing non-sequential numbering patterns
  • Looping identifiers: Where the next string isn’t always +1

⚙️ Example

LastCode := IncStr(LastCode, 5); // Jump by 5 in one go
        

🚧 Cases to Consider

  • It only increments the last numeric section of the string.
  • It respects the original number of digits (e.g., padding).
  • If there’s no number, it defaults to 1 and appends it.


IncStr('ABC', 3);  // Result: 'ABC3'
        

The new IncStr overload is a small change with big impact — making it easier to handle advanced string number incrementing without tedious code.


Stay Tuned for more.

For More visit https://ammolhsaallvi.blog/

To view or add a comment, sign in

More articles by Ammolh Saallvi

Insights from the community

Others also viewed

Explore topics