In Dynamics NAV 2009 RTC you have the new functionality with Notifications. It allows you to create notifications and send them to other users, so it shows up in their “My Notification” on the Role Center. The notifications are actually stored in the “Record Link” table as a BLOB field.
This is a great functionality, but as it is now, you can only see the notes from the My Notifications and the notification fact boxes. In this blog post i will take a look at how you can print these notes in a RTC/RDLC report.
Lets take closer look at what is stored:
In the table lets take a look at some of the fields that tell us we are dealing with a Notification:
- Type=Notification
- Notify, boolean that tells us if another user is to be notified
- To User ID, the User ID of the user to receive the notification
The actual data for the note is stored in the Note (BLOB) field. To get this to print on a report, lets just create a quick and simple report layout in the report designer. Just add the Note field (remember you need a CALCFIELDS on it) and put in the sourceexpression of a textbox in your report. On the RTC/RDLC report just add the new field and then test the report.
As you will notice it just prints: “#ERROR”. Hmm! This is due to the way the Note is stored in the database. The RTC clients writes the note through a BinaryWriter: http://msdn.microsoft.com/en-us/library/yzxa6408.aspx. As you can see the first bytes tells us the length of the string, and the remaining data is what we need to actually look at. In .NET that is very simple, just write a function to do that:
Public Function Convert2String(Value As Byte()) As String Try If Value.Length = 0 Then Return "" End If Dim utf8 As System.Text.UTF8Encoding = New System.Text.UTF8Encoding() Dim mem As New System.IO.MemoryStream() mem.Write(Value, 0, Value.Length) mem.Seek(0, System.IO.SeekOrigin.Begin) Dim reader As New System.IO.BinaryReader(mem, utf8) Return reader.ReadString() Catch ex As Exception Return ex.Message End Try End Function
As i usually code in C# and the RTC reports to my knowledge only works with VB.NET code i am using a neat little conversion tool, that can be found here: http://www.developerfusion.com/tools/convert/csharp-to-vb/. Also information for how the text is stored in the BLOB was found here: http://www.mibuso.com/forum/viewtopic.php?t=43416
TIP 1: Using the Try/Catch structure in the code, has been a great help in “debugging” my code in the RTC reports, as it would actually return any error messages from the Try section in the TextBox on the report, as well as help you figure out what Object data you are working with.
TIP 2: To make sure the code you have written in the RTC report can compile, you can do a build while you are in Visual Studio. Or just use the shortcust CTRL+B. That way you dont have to first save the report and wait for NAV to compile the code and return any errors.
In my next blog post, i will show you how to use the RTC notes in the classic client and NAS.
[…] Bron : Got C/AL Lees meer… […]
Søren,
did you finally wrote that blogpost you commented at the end of this one about working with notes in Classic? I’d like to be able to correctly print the notes (in reports) in Classic too (not only RTC).
Thanks and regards.
Hi there,
I managed to write Notes for NAV in the correct Blob format without creating and/or installing any third party apps… Just NAV Code.
I created a how-to here:
http://www.sbsintellect.co.za/index.php/2012/03/custom-automated-notes-in-dynamics-nav-rtc-2/
Regards,
Vincent Connell