Using Substring to replace CopyStr
BC 27.1 and later resolve a runtime error when using the Substring method with length parameters that exceed string boundaries, making it safe to replace CopyStr with Substring for improved code readability.

post The BC Docs Librarian
"With BC 27.1 and beyond, you can safely replace CopyStr with Substring to improve code readability!"
Key points
- Substring threw a runtime error in older versions such as BC 25.0 when the requested length went past the end of the string; a later BC 27.0 platform build fixed this
- BC 27.0 online has the fix but BC 27.0 on-premises does not; BC 27.1 is the first application version that has it in all cases
- CopyStr is still supported with no plans to obsolete it, so both methods can be used
- To use Substring safely, set the application property in app.json to 27.1.0.0 or higher; the runtime property and AL Language version do not matter
Quotes
- “With BC 27.1 and beyond, you can safely replace CopyStr with Substring to improve code readability!” (This signals when developers can confidently migrate to the newer, more readable method.)
- “Index and length must refer to a location within the string.” (This is the exact error message developers encountered when using Substring with invalid length parameters in earlier versions.)
- “BC 27.1 is the first application version having the fix in any case.” (This clarifies the minimum version requirement for guaranteed Substring support across all deployment types.)
Heads up
- breaking: “When we executed that code line in – let’s say – Business Central 25.0, then a runtime error was thrown.” (about version 25.0)
- gotcha: “BC 27.0 online would include the fix, but BC 27.0 on-premises does not.” (about version 27.0)
Context
- Features: Substring method, CopyStr method
- Versions: 27.1, 27.0, 25.0
Source: The BC Docs Librarian, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.