Blob to Stream to Text NAV 2013 r2

robertsstr
Member Posts: 4
Hello,
Issue is that in the following codeunit when creating subsequent notes only the 1st one successfully sends "Note" content.
This isn't an issue in NAV 2017 for some reason, but is a problem in NAV 2013 r2.
I Checked in Debugger, on first iteration NoteText = "test1",
On second iteration NoteText is empty.
what could be the reason? thank you. ;(
SalesSetup.GET();
CompInfo.GET();
PastTime := CURRENTDATETIME - (5 * 60 * 60 * 1000);
RecordLink.RESET();
RecordLink.SETRANGE(Created, PastTime, CURRENTDATETIME);
IF RecordLink.FINDFIRST() THEN BEGIN
REPEAT
UserSetup.RESET();
UserSetup.SETRANGE("User ID", RecordLink."To User ID");
UserSetup.SETFILTER("E-Mail", '<>%1', '');
RecordLink.SETFILTER(Notify, '<>%1', FALSE);
CLEAR(NoteStream);
CLEAR(NoteText);
RecordLink.CALCFIELDS(Note);
RecordLink.Note.CREATEINSTREAM(NoteStream, TEXTENCODING::UTF8);
NoteStream.READTEXT(NoteText);
CLEAR(NoteStream);
EmailMessage := DELSTR(NoteText, 1, 1);
IF UserSetup.FINDFIRST() THEN BEGIN
SMTP.CreateMessage(
CompInfo.Name,
SalesSetup."Send From E-mail",
UserSetup."E-Mail",
'Nuo: ' + RecordLink."User ID" + ' | ' + RecordLink.Description,
EmailMessage,
TRUE);
SMTP.TrySend;
END;
UNTIL RecordLink.NEXT() = 0;
END;
Issue is that in the following codeunit when creating subsequent notes only the 1st one successfully sends "Note" content.
This isn't an issue in NAV 2017 for some reason, but is a problem in NAV 2013 r2.
I Checked in Debugger, on first iteration NoteText = "test1",
On second iteration NoteText is empty.
what could be the reason? thank you. ;(
SalesSetup.GET();
CompInfo.GET();
PastTime := CURRENTDATETIME - (5 * 60 * 60 * 1000);
RecordLink.RESET();
RecordLink.SETRANGE(Created, PastTime, CURRENTDATETIME);
IF RecordLink.FINDFIRST() THEN BEGIN
REPEAT
UserSetup.RESET();
UserSetup.SETRANGE("User ID", RecordLink."To User ID");
UserSetup.SETFILTER("E-Mail", '<>%1', '');
RecordLink.SETFILTER(Notify, '<>%1', FALSE);
CLEAR(NoteStream);
CLEAR(NoteText);
RecordLink.CALCFIELDS(Note);
RecordLink.Note.CREATEINSTREAM(NoteStream, TEXTENCODING::UTF8);
NoteStream.READTEXT(NoteText);
CLEAR(NoteStream);
EmailMessage := DELSTR(NoteText, 1, 1);
IF UserSetup.FINDFIRST() THEN BEGIN
SMTP.CreateMessage(
CompInfo.Name,
SalesSetup."Send From E-mail",
UserSetup."E-Mail",
'Nuo: ' + RecordLink."User ID" + ' | ' + RecordLink.Description,
EmailMessage,
TRUE);
SMTP.TrySend;
END;
UNTIL RecordLink.NEXT() = 0;
END;
0
Answers
-
I found the problem. TEXTENCODING for some reason prevents it. When TEXTENCODING is removed it work fine, but users won't be able to use UTF8 letters.0
-
Hi
I guess it mostly depends on how you wrote the text to the note in the first place.
NAV 2013 R2 has code for this in Codeunit 454 Job Queue - Send Notification
I would assume this creates a Note BLOB content equal to what you would get by editing in the System Part with SystemPartID = Notes.
I would assume that this code should produce the same result asRecordLink.Note.CREATEOUTSTREAM(OStr,TEXTENCODING::UTF8); OStr.WriteText(NoteTextLine)
And therefore I would assume that your code would read the content correctly except for the following two potential problems:- READTEXT reads one line, not the entire contents of the note.
- As SystemUTF8Encoder.UTF8Encoding configures the encoder to use not BOM, I would expect the Note to contain no BOM. Therefore DELSTR(NoteText, 1, 1); removes the first character. Even if a BOM was present, I am not sure if that code would remove it, or if it would produce an incorrect byte stream by destroying the UTF-8 encoding. ClearUTF8BOMSymbols in Codeunit 6224 XML DOM Management (in newer versions of NAV / BC) uses more elaborate code in order to remove a BOM.
Furthermore I do not know what SMTP.CreateMessage supports in your version. The problem might be there entirely, and not at all in reading the Note content. Mail creation has always been a source of trouble as soon as you used any non-ASCII characters.0 -
[Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions