Sometimes you learn something new about Dynamics NAV features when you get an error first and then you troubleshoot the issue. This time, I have found myself “a bug or feature” for function STRSUBSTNO about which kriki blogged already (yes, the first thing you do, when you get an error message which you haven’t seen before, is hit google). For a moment I thought “well, one more undocumented feature”, but then… I found documentation for STRSUBSTNO on MSDN Library:
If this parameter is an expression that evaluates to Text or Code that is 512 or more characters, then a run-time error occurs.
Therefore, if you are creating filters dynamically (that’s where I have encountered the issue in the first place), don’t use STRSUBSTNO. If you will use this function, you will be limited to 512 characters. If you will choose another way (for example, if you would use Filter := Filter + ‘|’;) then your filter could go up to 1024 characters.
If you want to play around and to test STRSUBSTNO function, to replicate the issue in default CRONUS (UK) database, just create a simple codeunit:
So, two quick points to remember:
- Be careful with dynamic filters! They do tend to grow with time.
- Remember the limit (512 chars) of STRSUBSTNO function