Error: String is too small for insertion of %# fields

STRSUBSTNO - Error Message

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:

STRSUBSTNO - Documentation


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:

STRSUBSTNO - Example Replicate The Issue

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

Technorati Tags: , , , , ,

This entry was posted in Dynamics NAV / Navision, errors and tagged , , , , , . Bookmark the permalink.

One Response to Error: String is too small for insertion of %# fields

  1. Alex says:

    An interesting discussion is worth comment. I think that you should write more on this topic.

    Best regards Alex

Leave a Reply to Alex Cancel reply

Your email address will not be published. Required fields are marked *