Business Central 2025 wave 1 (BC26): Use new IncStr parameter to change integers by more than 1 in string variables (New IncStr method overload)

Dynamics 365 Business Central

Hi, Readers.
The public preview for Dynamics 365 Business Central 2025 release wave 1 (BC26) is available. Learn more: Link.

I will continue to test and share some new features that I hope will be helpful.

Use new IncStr parameter to change integers by more than 1 in string variables:

Business value:
For some time you’ve been able to increase a positive number or decrease a negative number inside a string variable by 1 using the IncStr method on Text types. This is useful when handling iterations, for example, involving number series. If you needed to make a change of more than 1, however, you had to write extensive custom logic. To help in these scenarios, the IncStr method now supports a new optional increments parameter to change more than 1.

https://learn.microsoft.com/en-us/dynamics365/release-plan/2025wave1/smb/dynamics365-business-central/use-new-incstr-parameter-change-integers-more-than-1-string-variables?wt.mc_id=DX-MVP-5004336

This is also mentioned in AL Language extension changelog Version 15.0:

New IncStr method overload
A new overload of the IncStr method was added to support an arbitrary positive increment. This allows for incrementing number series or other similar series by more than one position in one go.

https://marketplace.visualstudio.com/items/ms-dynamics-smb.al/changelog

As you might know, we can use Text.IncStr(Text) Method to increases a positive number or decrease a negative number inside a string by one (1).

For example,

With this wave (BC26), a new overload of the IncStr method is added to support an arbitrary increase or decrease of a number in a string variable. This allows for incrementing number series or other similar series by more than one position in one go.

A simple example: Using the new IncStr method overload with an increment parameter of 10.

The Increment parameter is of BigInteger data type, so negative number is also supported.

Other precautions are the same as those mentioned in Text.IncStr(Text) Method.
1. If String contains more than one number, then only the number closest to the end of the string is changed. For example, ‘A10B20’ is changed to ‘A10B21’ and ‘a12b12c’ to ‘a12b13c’.

2. If String contains a negative number, then it is decreased by one. For example, ‘-55’ is changed to ‘-56’.

You can add a negative number to this new parameter to increment the negative number.

3. Zero (0) is considered a positive number. Therefore, it is increased it by one. For example, ‘A0’ is changed to ‘A1’.

4. When String contains a number such as 99, it is increased to 100 and the length of the output string is: LEN(String) + 1. For example, ‘a12b99c’ is changed to ‘a12b100c’. (You can refer to the examples above)

5. If String does not contain any number, the output string is an empty string. For example, ‘aaa’ is changed to ”.

6. IncStr only increments integer numbers within strings, not decimals. For example, if you call IncStr on the string a99.99b then the result is a99.100b.

Small update, but it makes life easier. Give it a try!!!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL