Hi All,
I want to import an Xml file (by XmlPort) which contains an element with a Comment (element name is FInalReportComment). This Comment could be up to 1000 characters. The comment should be stored in the RecordLink table, in the Blob field. The Problem is that the whole text is imported, but when I process it to the Blob field I miss some leading characters, and a lot of text at the end. What is the cause of this behaviour?
The Xml Element in the XmlPort is of sourcetype Text, with TextType BitText. The Xml Port is set to encoding UTF8, but also with UTF16 I do have the same issue.
The most easy is the following code:
Notes.Note.CREATEOUTSTREAM(OutStream);
FinalReportComment.WRITE(OutStream);
// Where Notes is recordlink table
// And FinalReportComment is the BigText Xml element
I also tried the following code (binary):
Notes.Note.CREATEOUTSTREAM(OutStream);
Size1 := FinalReportComment.LENGTH MOD 128;
Size2 := FinalReportComment.LENGTH DIV 128;
IF Size2 = 0 THEN BEGIN
Size := 'x';
Size[1] := Size1;
END ELSE BEGIN
Size := 'xx';
Size[1] := Size1 + 128;
Size[2] := Size2;
END;
OutStream.WRITETEXT(Size);
FinalReportComment.WRITE(OutStream);
Does work better, but it will process about a couple of hundred characters and not the total of 1000 characters.
Can anybody help me to solve this issue? What is missing...
Thanks in advance...
0
Comments
and read the comments. That should get you home...
Gunnar Gestsson
Microsoft Certified IT Professional
Dynamics NAV MVP
http://www.dynamics.is
http://Objects4NAV.com
Hi thegunzo,
Thanks for your reply. I already used this kind of code, but the strange behaviour of this solution is that there are only 805 characters processed.
I created a test codeunit with the codelines shown below. It is just a text (from wiki) as a Bigtext variable and import it to the Item table Notes. And the result is only 805 characters available in the Note.
////
MessageText.ADDTEXT('Writing is a medium of communication that represents language through the inscription of signs and symbols. In most languages,');
MessageText.ADDTEXT('writing is a complement to speech or spoken language. Writing is not a language but a form of technology. Within a language');
MessageText.ADDTEXT('system, writing relies on many of the same structures as speech, such as vocabulary, grammar and semantics, with the added');
MessageText.ADDTEXT('dependency of a system of signs or symbols, usually in the form of a formal alphabet. The result of writing is generally called');
MessageText.ADDTEXT('text, and the recipient of text is called a reader. Motivations for writing include publication, storytelling, correspondence');
MessageText.ADDTEXT('and diary. Writing has been instrumental in keeping history, dissemination of knowledge through the media and the formation');
MessageText.ADDTEXT('of legal systems.');
MessageText.ADDTEXT('As human societies emerged, the development of writing was driven by pragmatic exigencies such as exchanging information,');
MessageText.ADDTEXT('maintaining financial accounts, codifying laws and recording history. Around the 4th millennium BCE, the complexity of trade');
MessageText.ADDTEXT('and administration in Mesopotamia outgrew human memory, and writing became a more dependable method of recording and presenting');
MessageText.ADDTEXT('transactions in a permanent form.[1] In both Ancient Egypt and Mesoamerica writing may have evolved through calendrics and a');
MessageText.ADDTEXT('political necessity for recording historical and environmental events.');
Item.GET(1000);
RecRef.GETTABLE(Item);
Bookmark := FORMAT(RecRef.RECORDID,0,10);
Notes.INIT;
Notes."Record ID" := RecRef.RECORDID;
Notes.URL1 :=
'dynamicsnav://localhost:7046/DynamicsNAV71/CRONUS%20Nederland%20BV/runpage?page=30&personalization=30&bookmark=' +
Bookmark +
'&mode=Edit';
Notes.Description := FORMAT(RecRef.RECORDID,0,1);
Notes.Type := Notes.Type::Note;
Notes.Created := CURRENTDATETIME;
Notes."User ID" := USERID;
Notes.Company := COMPANYNAME;
Notes.Note.CREATEOUTSTREAM(StreamOut);
Encoding := Encoding.UTF8;
BinaryWriter := BinaryWriter.BinaryWriter(StreamOut,Encoding);
BinaryWriter.Write(MessageText);
Notes.INSERT;
////
Do you or anybody else have any idea what causes this behaviour?
Thanks!
Don
Gunnar Gestsson
Microsoft Certified IT Professional
Dynamics NAV MVP
http://www.dynamics.is
http://Objects4NAV.com
Conclusion is that there is no difference between Text or BigText.
Add two lines.
Encoding := Encoding.UTF8;
BinaryWriter := BinaryWriter.BinaryWriter(StreamOut,Encoding);
BinaryWriter.Write(MessageText);
BinaryWriter.Flush;
BinaryWriter.Close;
Notes.INSERT
Gunnar Gestsson
Microsoft Certified IT Professional
Dynamics NAV MVP
http://www.dynamics.is
http://Objects4NAV.com
Sorry for my late reaction.
I added the lines to flush and close the object, but this didn't affect the behaviour. There are only about 800 characters processed (depending on the text).
Are there more ideas to solve this (or somebody else)? I also didn't try the solution 'ppavuk' mentioned.
Thanks and regards,
Don
Encoding := Encoding.ANSI; instead of Encoding := Encoding.UTF8;?
We found it, and what a blind spot it is in Dynamics NAV! The case is that the whole text is in the RecordLink Blob field, but the Notes viewer doesn't show all characters. So I thought that the message was not processed/saved well in the database, but it is the viewer that causes this issue.
I think this has to be reported to Microsoft. Or does anybody have any clue why this is the behaviour of the viewer?
Regards,
Don