Rashed Amini

The ara3n weblog

String Implementation in NAV

25th November 2010

If you have developed with any OCX or COM objects in Dynamics NAV, you have probably run into the following error. “The length of the text string exceeds the size of the string buffer.” The reason you would get this error is because you were passing a string from COM object to NAV. NAV limits COM object string length to 1024 characters. In older version it was 250 characters but they increased it to 1024 characters. The workaround this limitation you had to build a COM wrapper for the DLL file and split the string into 1024 or smaller sizes and pass it to NAV. This solution was cumbersome with rolling it out on every PC and maintaining it, as well compiling the objects if you didn’t have the wrapper. I had suggested to MS to remove this limit and they are working on it. Freddy who was in one of those meetings with MS suggested that you could use Variant type to get around the problem. I didn’t try to look for a solution until recently I received an email from a client that they were running into this problem. Here is the solution. This only works on Role Tailored client and on classic you will still receive the error. If you are running on classic, you could use NAV web service and allow it to run the NAV code.
In the code below, xmlDom.xml returns a string of the whole xml as string, which is more than 1024 characters.


IF ISCLEAR(xmlDom) THEN
CREATE(xmlDom);
xmlDom.async(FALSE);
xmlDom.load('C:\Temp\NAVSetupPORT.xml');

MyVariant := xmlDom.xml;
BText.ADDTEXT(FORMAT(MyVariant));
BText.GETSUBTEXT(mytext,1,1024);
MESSAGE(mytext);
CLEAR(xmlDom);

Name DataType
MyVariant Variant
xmlDom Automation 'Microsoft XML, v6.0'.DOMDocument
mytext Text 1024
BText BigText

NAV 2009 R2 which is being released on December 15th 2010 will allow developer in NAV to use the .NET framework in NAV. NAV has introduced a new object type DotNet. The solution will work with DotNet objects as well. Here is an example code.

xmlDom := xmlDom.XmlDocument;
xmlDom.Load('C:\Temp\NAVSetupPORT.xml');
MyVariant := xmlDom.InnerXml;
BText.ADDTEXT(FORMAT(MyVariant));
BText.GETSUBTEXT(mytext,1,1024);
MESSAGE(mytext);

CLEAR(xmlDom);

The above code is very similar to the COM example except xmlDom is DotNet object type with subtype Systeml.xml.XmlDocument .
‘System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.System.Xml.XmlDocument

2 Responses to “String Implementation in NAV”

  1. kriki Says:

    Important note for .NET in NAV2009R2: you can ONLY use it with RTC! NOT with the classic client!

  2. ara3n Says:

    Yes, .NET can only be used in RTC or using NAV web service. If you want to use it in classic you have to use web service.

Leave a Reply

You must be logged in to post a comment.