Reading/writing Notes with DotNet variables

mathieukmathieuk Member Posts: 15
edited 2015-06-20 in NAV Three Tier
Hi guys,
I've been stuck on that for a little while and I hope someone can help me.
I'm using NAV 2009 R2.
I need to read/write notes in a codeunit. This codeunit is then going to be used by a web service.
This is my function to write a note

NotificationText.ADDTEXT(NotificationText2);
RecordLink.INIT;
RecordLink.”Record ID” := RecRef.RECORDID;
RecordLink.URL1 := CreateURL(RecRef,ObjectID);
RecordLink.Description := Caption;
RecordLink.Type := RecordLink.Type::Note;
RecordLink.Created := CURRENTDATETIME;
RecordLink.”User ID” := USERID;
RecordLink.Company := COMPANYNAME;
RecordLink.Notify := TRUE;
RecordLink.”To User ID” := USERID;
RecordLink.INSERT(TRUE);
RecordLink.Note.CREATEOUTSTREAM(OutStream);

Encoding := Encoding.GetEncoding(437);
BinaryWriter := BinaryWriter.BinaryWriter(OutStream,Encoding);
BinaryWriter.Write(FORMAT(NotificationText));
OutStream := BinaryWriter.BaseStream;

RecordLink.MODIFY();

My parameters are
RecRef RecordRef
ObjectID Text 50
NotificationText2 Text 1024
Caption Text 50

and my variables are
OutStream OutStream
BinaryWriter DotNet ‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.System.IO.BinaryWriter
Encoding DotNet ‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.System.Text.Encoding
RecordLink Record Record Link
NotificationText BigText

My issue is on this line:
BinaryWriter := BinaryWriter.BinaryWriter(OutStream,Encoding);

I get this error: Unknown Type ''.
Does anyone know what is the issue?
Thanks guys

Comments

  • mathieukmathieuk Member Posts: 15
    Does anyone have an idea?
    Thanks
  • amandabzamandabz Member Posts: 5
    Having the same issue.. Did you ever figure this out?

    Thanks!!
    Amanda
  • BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    We did provide a similar piece of code in NAV2013, codeunit 454 "Job Queue - Send Notification", where the Job Queue sends a notification to the user. The message format is in RTF, which includes one or two leading bytes of information about the message length.
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • mathieukmathieuk Member Posts: 15
    Sorry for the late answer.
    The code I've posted is working for NAV 2013 but it is not working for NAV 2009.
    So, after spending hours trying to find a solution I actually gave up and used the comments instead of the notes. Much easier to manage.

    Still interested to know if there is a solution though.
    Cheers
  • SogSog Member Posts: 1,023
    It seems I have the same error, but the line it errors out to is the following: Encoding := Encoding.GetEncoding(437);

    It appears because Encoding doesn't have a constructor, NAV2009 cannot handle it.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • thegunzothegunzo Member Posts: 274
    Try

    Encoding := Encoding.Default;

    to construct the Encoding variable.
    ________________________________
    Gunnar Gestsson
    Microsoft Certified IT Professional
    Dynamics NAV MVP
    http://www.dynamics.is
    http://Objects4NAV.com
  • amandabzamandabz Member Posts: 5
    While I can't say this is the correct way... I have found a solution. I found the unknown type to be in line "BinaryWriter.BinaryWriter(OutStream,Encoding)", the unknown being the Variable: "Outstream - DataType Outstream". I created another variable, "Outstream1 Datatype DotNet - 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Stream" and modified the code as shown:
      Note.CREATEOUTSTREAM(OutStream);
      OutStream1 := OutStream;
      
      Encoding := Encoding.GetEncoding(437);
      BinaryWriter := BinaryWriter.BinaryWriter(OutStream1,Encoding);
      BinaryWriter.Write(FORMAT(Notification));
      OutStream := BinaryWriter.BaseStream;
    

    Sog, while I didn't get an unknown error in line Encoding := Encoding.GetEncoding(437);, I did receive an error when I originally pasted and copied the dotnet variable. GetEncoding was not an my Encoding C/AL Symbols menu. I entered manually to ensure it was pasted correctly, found what I had pasted was not my Processor Architecture type. Not sure if you reviewed already, but thought I would mention just in case.

    Hope this helps!
  • absolutelyfreewebabsolutelyfreeweb Member Posts: 104
    Not entirely related but I got the unknown type '' error when trying to call a function with a string parameter.
    Works in newer version but not 2009. Instead of calling it with a text variable, I made it a big text and assigned the text to it with addText, like this:

    gFolderPath.ADDTEXT(edisetup."XML Source Document Folder");

    After that it was OK to use it without error:

    obj := fold.GetFiles(gFolderPath);
Sign In or Register to comment.