IncStr() now includes a new overloaded method—use it wisely!

The introduction of the overloaded IncStr function in the AL compiler for Microsoft Dynamics 365 Business Central, which now accepts an increment value greater than 1 (e.g., IncStr(‘aaa001’, 10) returning aaa011), is a significant enhancement for developers working with AL and Business Central. This functionality allows for more flexible string manipulation, particularly when incrementing numeric portions of strings by arbitrary values.

Use Case: Custom Inventory Lot or Serial Number Sequencing

Manufacturing and distribution companies using Business Central often manage inventory with lot or serial numbers that include a prefix and a numeric component, such as LOT-A001, LOT-A002, or SER2025-001. In some cases, businesses may need to increment these numbers by a value greater than 1 to align with production batches, skip reserved ranges, or synchronize with external systems.

Scenario: A manufacturer produces items in batches of 5 units, and each batch requires a unique lot number starting from LOT-B001. To streamline inventory tracking, the system must generate lot numbers that jump by 10 (e.g., LOT-B001, LOT-B011, LOT-B021, LOT-B031, LOT-B041) to reflect the batch size.

procedure GenerateLotNumbers(BaseLot: Code[20];
                                BatchSize: Integer;
                                NumberOfBatches: Integer;
                                var LotNumbers: List of [Code[20]])
    var
        CurrentLot: Code[20];
        i: Integer;
    begin
        CurrentLot := BaseLot; // e.g., 'LOT-B001'
        LotNumbers.Add(CurrentLot);
        for i := 1 to NumberOfBatches - 1 do begin
            CurrentLot := IncStr(CurrentLot, BatchSize); // Increment by BatchSize
            LotNumbers.Add(CurrentLot);
        end;
    end;

We would call the function as below:

GenerateAndDisplay('LOT-B001', 10, 5);

But what about calling the function with a negative increment?

GenerateAndDisplay('LOT-B001', -10, 5);

Or,

        GenerateAndDisplay('LOT', 10, 5); // no numeric value
        GenerateAndDisplay('', 10, 5); // no numeric, no string
        GenerateAndDisplay('001', 10, 5); // just numeric

About all these use cases watch this 5-minute Youtube video:

Need an AL extension built, or one fixed that does not work right? I write AL for companies and for other partners. AL development →