Reading/writing Notes with DotNet variables

mathieukmathieuk Posts: 15Member
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

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;

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


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

and my variables are
OutStream OutStream
BinaryWriter DotNet ‘mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089′.System.IO.BinaryWriter
Encoding DotNet ‘mscorlib, Version=, 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


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

  • BardurKnudsenBardurKnudsen Posts: 137Member, Microsoft Employee
    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 Posts: 15Member
    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.
  • SogSog Posts: 1,023Member
    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|
  • thegunzothegunzo Posts: 274Member

    Encoding := Encoding.Default;

    to construct the Encoding variable.
    Gunnar Gestsson
    Microsoft Certified IT Professional
    Dynamics NAV MVP
  • amandabzamandabz Posts: 5Member
    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=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Stream" and modified the code as shown:
      OutStream1 := OutStream;
      Encoding := Encoding.GetEncoding(437);
      BinaryWriter := BinaryWriter.BinaryWriter(OutStream1,Encoding);
      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 Posts: 100Member
    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.