Tuesday 1 March 2016

String truncation in AX7

This isn’t really a new feature, since it has been in place in the legacy product for the whole life of Dynamics AX. However, when code is executed in IL in prior versions of Dynamics AX, the automatic string truncation described here doesn’t take place.

Because it’s not a well-known or well understood feature, we’ll briefly discuss it here.
String values can be declared in X++ to contain a maximum number of characters. Typically, this is achieved by encoding this information in an extended data type, as shown below: Credit card numbers cannot exceed 20 characters.

StringTruncationSolutionExplorer_DebugFeatures
It’s also possible to specify length constraints directly in the X++ syntax:
str 20 creditCardNumber;
All assignments to these values are implicitly truncated to this maximum length.

Exercise

Run the following code in the debugger by including it in a static main method:
creditCardNumber = "12345678901234567890Excess string";

No comments:

Post a Comment