Create note - Record Link formatting problem when saving

PablogrindPablogrind Member Posts: 13
With the same code and only changing the text it produces different results
procedure FillNote()
    var
        Customer: Record Customer;
        RecordLink: Record "Record Link";
        outStr: OutStream;
        MyInStream: InStream;
    begin
        Customer.GET('00000006');
        Clear(RecordLink);
        RecordLink.Init();
        RecordLink."Record ID" := Customer.RecordId();
        RecordLink.Type := RecordLink.Type::Note;
        RecordLink."Link ID" := 0;
        RecordLink.Created := CurrentDateTime;
        RecordLink."User ID" := USERID;
        RecordLink.Company := CompanyName;

        RecordLink.Note.CreateOutStream(outStr, TextEncoding::UTF8);
        outStr.WRITETEXT('1111111111111 2222222222222 33333333333333 444444444444 555555');

        if RecordLink.Insert(true) then
            Message('Si')
        else
            Message('No');
    end;

RESULT:

8z9n36ydfzcs.png
the text is truncated
procedure FillNote()
    var
        Customer: Record Customer;
        RecordLink: Record "Record Link";
        outStr: OutStream;
        MyInStream: InStream;
    begin
        Customer.GET('00000006');
        Clear(RecordLink);
        RecordLink.Init();
        RecordLink."Record ID" := Customer.RecordId();
        RecordLink.Type := RecordLink.Type::Note;
        RecordLink."Link ID" := 0;
        RecordLink.Created := CurrentDateTime;
        RecordLink."User ID" := USERID;
        RecordLink.Company := CompanyName;

        RecordLink.Note.CreateOutStream(outStr, TextEncoding::UTF8);
        outStr.WRITETEXT('AAA BBB CCC DDD EEE FFF');

        if RecordLink.Insert(true) then
            Message('Si')
        else
            Message('No');
    end;

RESULT:

glhdik0xqm54.png
the text is invalid

changed to TextEncoding::Windows I have the same result, what could it be?

Answers

  • AlexeyShaminAlexeyShamin Member Posts: 80
    try like below (I got it from mibuso):

    function AddMemo(loc_rec : Record "Payment Lines";ApproveComment : Text[250])
    SystemUTF8Encoder := SystemUTF8Encoder.UTF8Encoding;
    SystemByteArray := SystemUTF8Encoder.GetBytes(ApproveComment);

    RecLink.INIT;
    RecLink.Type := RecLink.Type::Note;
    RecLink.Created := CURRENTDATETIME;
    RecLink."Record ID" := loc_rec.RECORDID;
    RecLink.Description := ApproveComment;
    IF MailAdressText <>'' THEN
    RecLink."User ID":= GetUserByEmail(MailAdressText);
    IF RecLink."User ID" = '' THEN
    RecLink."User ID" := USERID;
    RecLink.Company := COMPANYNAME;
    RecLink.CALCFIELDS(Note);
    CLEAR(RecLink.Note);
    RecLink.Note.CREATEOUTSTREAM(OutStr);
    x := SystemByteArray.Length DIV 128;
    IF x > 1 THEN
    y := SystemByteArray.Length - 128 * (x - 1)
    ELSE
    y := SystemByteArray.Length;
    c1 := y;
    OutStr.WRITE(c1);
    IF x > 0 THEN BEGIN
    c2 := x;
    OutStr.WRITE(c2);
    END;
    FOR i := 0 TO SystemByteArray.Length - 1 DO BEGIN
    c1 := SystemByteArray.GetValue(i);
    OutStr.WRITE(c1);
    END;

    RecLink.INSERT;


    RecLink Record Record Link
    OutStr OutStream
    Encoding TextEncoding
    x Integer
    y Integer
    i Integer
    c1 Char
    c2 Char
  • AlexDenAlexDen Member Posts: 86
    Hello,

    Instead of
    RecordLink.Note.CreateOutStream(outStr, TextEncoding::UTF8);
    outStr.WRITETEXT('AAA BBB CCC DDD EEE FFF');
    

    you should use
    TypeHelper.WriteRecordLinkNote(RecordLink,'AAA BBB CCC DDD EEE FFF');
    

    TypeHelper is Codeunit 10 "Type Helper".
    You can see an example of use in Codeunit 454.
  • PablogrindPablogrind Member Posts: 13
    Awesome, thankss
Sign In or Register to comment.