How to create recordlink or notify by C/AL-Code

RogerRoger Member Posts: 57
edited 2011-02-04 in NAV Tips & Tricks
If you want to create a notify message which is shown on the start page of a role center you can
use the following example.

It is importent to set the lenght of the text in a CHAR variable in front of the text.

Define the following variables in the locals of the function:
OutStream DataType OutStream
Text DataType Text 250
NewID DataType Integer
LenChar DataType Char
Text := 'Dies ist ein weiterer wertvoller Hinweis';
LenChar := STRLEN(Text);

Text := FORMAT(LenChar) + Text;

Cont.GET('1000');
NewID := Cont.ADDLINK('dynamicsnav://dell-rotsch:7046/myCharity/myCharity/runpage?page=5050&mode=Edit',
                      'Über eigene Funktion erstellt');

RecordLink.GET(NewID);

RecordLink.CALCFIELDS(Note);
RecordLink.Note.CREATEOUTSTREAM(OutStream);
OutStream.WRITE(Text);

RecordLink.Type := RecordLink.Type::Note;
RecordLink.Notify := TRUE;
RecordLink."To User ID" := USERID;

RecordLink.MODIFY;
Many thanks, Roger

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • arnimarnim Member Posts: 1
    Hello Roger,

    do you have any idea how to post more the 250 digits in a note? Because a char can have as max value 250.

    Thanks in advance

    arnim
  • JohnConJohnCon Member Posts: 55
    arnim wrote:
    Hello Roger,

    do you have any idea how to post more the 250 digits in a note? Because a char can have as max value 250.

    Thanks in advance

    arnim


    Has anyone figured out how to import notes that are greater than 250 characters?
    Thanks...
  • RogerRoger Member Posts: 57
    arnim wrote:
    do you have any idea how to post more the 250 digits in a note? Because a char can have as max value 250.

    I've used the following code for creating notes
    RecordLink.CALCFIELDS(Note);
    RecordLink.Note.CREATEOUTSTREAM(OStream);
    OStream.WRITE(FORMAT(LenChar) + _Note);
    RecordLink.Type := RecordLink.Type::Note;
    RecordLink.Notify := _Notify;
    RecordLink."To User ID" := _UserID;
    
    RecordLink.MODIFY;
    

    The variabale _Note is a text variable which have a length of 1024.
    I mean, you should be able to add more of such variable using the +
    I've not tested it
    Many thanks, Roger
  • JohnConJohnCon Member Posts: 55
    Roger wrote:
    arnim wrote:
    do you have any idea how to post more the 250 digits in a note? Because a char can have as max value 250.

    The variabale _Note is a text variable which have a length of 1024.
    I mean, you should be able to add more of such variable using the +
    I've not tested it

    You get an error when assign LenChar to the length of the text string when LenChar is a char type variable.
    Is there another way to assign the length?
  • northernernortherner Member Posts: 67
    If your text is longer than 255 characters, you need to include a second Char. The formula is in this code...

    TextToWriteAsNote Text 1024
    NoteLength Integer
    Char1 Char
    Char2 Char
    NoteLength := STRLEN(TextToWriteAsNote);
    IF NoteLength <= 255 THEN BEGIN
      Char1 := NoteLength;
      Char2 := 1;
    END ELSE BEGIN
      Char1 := 128 + (NoteLength - 256) MOD 128;
      Char2 := 2 + (NoteLength - 256) DIV 128;
    END;
    TextToWriteAsNote := FORMAT(Char1) + FORMAT(Char2) + TextToWriteAsNote;
    
Sign In or Register to comment.