Blob to Stream to Text NAV 2013 r2

robertsstrrobertsstr Member Posts: 4
edited 2024-06-04 in NAV Three Tier
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;

Answers

  • robertsstrrobertsstr Member Posts: 4
    edited 2024-05-16
    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.
  • vaprogvaprog Member Posts: 1,139
    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 as
    RecordLink.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:
    1. READTEXT reads one line, not the entire contents of the note.
    2. 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.
  • krikikriki Member, Moderator Posts: 9,110
    [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!


Sign In or Register to comment.