Tuesday, November 10, 2015

How to Read/Write Notes in Navision using C/AL

question-686336_1920

In this post I will discuss how to read the notes and how to create the notes programmatically. When you create a note where the data is saved in the Navision ? I have seen this question being asked several times in the community forum. The answer is the notes are saved in binary format in a blob field (Note) in the Record Link table (2000000068) and the way it maps to the record is using Record ID.

Read Notes:

To read notes you need to find the “Record ID” of the record using Record Reference and then use that to filter the Record Link table and then convert value in the blob field (Note) into readable text.

In the below example the ReadNotes function takes SalesHeader as parameters and displays the first note associated with it.

Write Notes:

To create note once we again need to get the “Record ID” of the record which can be retrieved using Record Reference, and we also need to convert the text into bytes to store in the “Note” Blob Field. Since the Record Link primary key Link ID is set to Auto Increment we don’t need to find the next available “Link ID”, as INSERT statement will take care of retrieving it and assigning it.

There are two helper functions below SetText and HtmlEncode, you need these functions to write notes.

PROCEDURE ReadNotes@1240060000(SalesHeader@1240060003 : Record 36);
    VAR
      RecordLink@1240060000 : Record 2000000068;
      NoteText@1240060001 : BigText;
      Stream@1240060002 : InStream;
      RecRef@1240060004 : RecordRef;
    BEGIN
      RecRef.GETTABLE(SalesHeader);
      RecordLink.SETRANGE("Record ID",RecRef.RECORDID);
      IF RecordLink.FINDFIRST THEN BEGIN
        REPEAT
          RecordLink.CALCFIELDS(Note);
          IF RecordLink.Note.HASVALUE THEN BEGIN
            CLEAR(NoteText);
            RecordLink.Note.CREATEINSTREAM(Stream);
            NoteText.READ(Stream);
            NoteText.GETSUBTEXT(NoteText, 2);
            MESSAGE(FORMAT(NoteText));
          END;
       UNTIL RecordLink.NEXT = 0;
      END;
    END;

    PROCEDURE WriteNote@1240060001();
    VAR
      LinkID@1240060000 : Integer;
      Customer@1240060001 : Record 18;
      RecRef@1240060002 : RecordRef;
      RecordLink@1240060003 : Record 2000000068;
    BEGIN
      Customer.GET('10000');
      RecRef.GETTABLE(Customer);
      RecordLink.INIT;
      RecordLink."Link ID" := 0;
      RecordLink."Record ID" := RecRef.RECORDID;
      RecordLink.URL1 := GETURL(CLIENTTYPE::Current, COMPANYNAME, OBJECTTYPE::Page, PAGE::"Customer Card");
      RecordLink.Type := RecordLink.Type::Note;
      RecordLink.Created := CURRENTDATETIME;
      RecordLink."User ID":=USERID;
      RecordLink.Company:=COMPANYNAME;
      RecordLink.Notify := TRUE;
      SetText('Test Note For the Customer 10000',RecordLink);
      RecordLink.INSERT;
    END;

    LOCAL PROCEDURE SetText@4(NoteText@1001 : Text;VAR RecordLink@1000 : Record 2000000068);
    VAR
      SystemUTF8Encoder@1011 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.UTF8Encoding";
      SystemByteArray@1010 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array";
      OStr@1008 : OutStream;
      s@1007 : Text;
      lf@1006 : Text;
      c1@1005 : Char;
      c2@1004 : Char;
      x@1003 : Integer;
      y@1002 : Integer;
      i@1009 : Integer;
    BEGIN
      s := NoteText;
      SystemUTF8Encoder := SystemUTF8Encoder.UTF8Encoding;
      SystemByteArray := SystemUTF8Encoder.GetBytes(s);

      RecordLink.Note.CREATEOUTSTREAM(OStr);
      x := SystemByteArray.Length DIV 128;
      IF x > 1 THEN
        y := SystemByteArray.Length - 128 * (x - 1)
      ELSE
        y := SystemByteArray.Length;
      c1 := y;
      OStr.WRITE(c1);
      IF x > 0 THEN BEGIN
        c2 := x;
        OStr.WRITE(c2);
      END;
      FOR i := 0 TO SystemByteArray.Length - 1 DO BEGIN
        c1 := SystemByteArray.GetValue(i);
        OStr.WRITE(c1);
      END;
    END;

    LOCAL PROCEDURE HtmlEncode@20(InText@1000 : Text[1024]) : Text[1024];
    VAR
      SystemWebHttpUtility@1001 : DotNet "'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Web.HttpUtility";
    BEGIN
      SystemWebHttpUtility := SystemWebHttpUtility.HttpUtility;
      EXIT(SystemWebHttpUtility.HtmlEncode(InText));
    END;






The two above functions SetText and HtmlEncode are copied from the standard Navision Codeunit (454 Job Queue - Send Notification)


Download the object from this link Notes Management


Please leave your comments, feedback or any suggestions you have for me to improve my blog and also if you have any questions, feel free to post.

Share:

33 comments:

Unknown said...

Great post.
Regards,
DOTNET Training Institutes in Chennai

Unknown said...

Thanks for sharing such a useful post with us.
Android course in Chennai | Java course in chennai

Unknown said...

Thank you, this one really helped me :)!

Unknown said...

Great Post Suresh and just what I was looking for. Much Appreciated!

Regards
tui

Aurthur said...

Really useful to me.I would like to learn more about Java. Continue sharing.
Thanks,
Java Training in Chennai | Java courses in Chennai | Java J2EE Training in Chennai

Hung H. said...

Thank you Kulla!

aszabo said...

Hello. i have a little problem with it.
the user who have to get the message is get it, but he can't open the page with double click on the notificaton. Can you tell me how can i call the sesond procedure when i'm trying to send a notes?

Suresh Kulla said...

Hello,

Can you please explain me in detail, what is the second procedure you are referring to ?

Thanks
Suresh

Karthika Shree said...
This comment has been removed by the author.
Karthika Shree said...

Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
Java Training in Chennai

Anonymous said...

Hello!

Thank you for your great post!

Regards
Leslie


Rishi said...

Hi Suresh,

Thanks for Writing this superb blog.
Your Blogs are always helpful.

Sai Elakiyaa said...

Well said!! much impressed by reading your article. Keep writing more.

Software testing training in chennai
Salesforce Training in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Training in Chennai
JAVA Training in Chennai
Best JAVA Training institute in Chennai

jefrin said...

Amazing to read thanks for the author

salesforce training in chennai

janakikrishnan said...

Looks great and every freshers want to go through your blog for their growth.
java training in coimbatore
java training institute in coimbatore
java training in bangalore
Java Training Institutes in Bangalore
java training in madurai
best java training institute in madurai

lekha mathan said...

This is really a valuable post... The info shared is helpful and valuable. Thank you for sharing.
Aviation Academy in Chennai
Air hostess training in Chennai
Airport management courses in Chennai
Ground staff training in Chennai
aviation training in Chennai
air hostess academy in Chennai
Airline Courses in Chennai
Ground staff training in Chennai

Anjali Siva said...

Thanks for this article, your post helps me to understand the future and career prospects. Keep updating your blog with the latest information.
Salesforce Training in Chennai
Salesforce course in Chennai
AngularJS Training in Chennai
ccna course in Chennai
PHP Training in Chennai
gst Training in Chennai
Tally course in Chennai
Salesforce Training in Anna Nagar
Salesforce course

luckys said...

age calculator

Unknown said...

Came to this late, but very glad it is still here. Works like a charm.

Only one question-it seems HtmlEncode is never called?

Thanks so much!

Kajal said...

very helpful article, it's quite interesting and informative thank you for sharing it, personally i like ihomcare for maid for elderly.

Galia Co Hagan said...

Great Article. Thank you for sharing! Really an awesome post for every one.

IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

JavaScript Training in Chennai

JavaScript Training in Chennai

dataexpert said...

Very nice job... Thanks for sharing this amazing and educative blog post! ExcelR Digital Marketing Class In Pune

CloudLearn ERP said...

I personally think your article is fascinating, interesting and amazing. I share some of your same beliefs on this topic. I like your writing style and will revisit your site.
Best Data Science training in Mumbai

Data Science training in Mumbai

amc stars said...

دانلود کتاب صوتی قدرت عادت دانلود کتاب صوتی قدرت عادت
دانلود کتاب صوتی قدرت عادت دانلود کتاب صوتی قدرت عادت

ve may bay tet said...

Chuyên vé máy bay Aivivu, tham khảo

vé máy bay đi Mỹ bao nhiêu

vé máy bay từ mỹ về việt nam

ve may bay tu canada ve viet nam

Lịch bay từ Hàn Quốc về Việt Nam tháng 7

Digital Marketing training - 360DigiTMG said...

Truly incredible blog found to be very impressive due to which the learners who ever go through it will try to explore themselves with the content to develop the skills to an extreme level. Eventually, thanking the blogger to come up with such an phenomenal content. Hope you arrive with the similar content in future as well.
Digital Marketing training

senthilpraveen said...

It’s a nice blog with very useful information!!!
Web Designing Course in chennai
PHP Training in Chennai
Spoken English Classes in Chennai
German Classes in Chennai
Salesforce Training in Chennai
IELTS Coaching in Chennai

Dynatech Solutions said...

Microsoft Dynamics 365 business Central is a comprehensive business management solution designed for small to medium-sized businesses. It helps to increase financial visibility, optimize supply chain, boost sales and service and deliver projects on time.

To adopt the solution, get in touch with a microsoft business central partner today!

Diyalabs said...

Thanks for sharing such a helpful, and understandable blog. I really enjoyed reading it.

Robots for kids
Robotic Online Classes
Robotics School Projects
Programming Courses Malaysia
Coding courses
Coding Academy
coding robots for kids
Coding classes for kids
Coding For Kids

Data Science Course in Bhilai - 360DigiTMG said...

Wonderful blog found to be very impressive to come across such an awesome blog. I should really appreciate the blogger for the efforts they have put in to develop such an amazing content for all the curious readers who are very keen of being updated across every corner. Ultimately, this is an awesome experience for the readers. Anyways, thanks a lot and keep sharing the content in future too.

Data Science Course in Bhilai

Anonymous said...

Whatsapp Number Call us Now! 01537587949
It Training In Dhaka
USA pone web iphone repair USA
USA SEX WEB careful
bd sex video B tex
bd sex video sex video
bd sex video freelancing course

Morgan said...

If you are running late, you have the convenience of a high-quality printer right in your own office. If you discover you need more copies of the document, you can print more immediately. renting impresoras sevilla

Himanshu Tyagi said...

THANK YOU for this amazing and for sharing this blog with us, it is very helpful.
please keep updated us more about like this type of blog.
If someone is looking for the best java training institute for software training in Ghaziabad, java training institute
It is the best place from where you get the practical knowledge of java training institute here. You will be an expert in this field after doing the java training.