Remember the last post? I needed a way to easily view and edit large chunks of text, and used Memo BLOBs for that.
What I was actually after was a way to display NAV objects in text format in RTC.
While the Memo trick worked up to a point, it didn’t play nicely with the long lines of code found in NAV objects, and multi-line textbox doesn’t let you scroll horizontally.
While trying to come up with a way to solve this, I had to do some debugging for something unrelated.
If you ever used debugger in NAV 2013 or later, I am sure you know where this is going…
Enter: Code Viewer control
I looked at the way Code Viewer control was used in standard NAV debugger. For reference, take a look at pages 9500 and 9504 in NAV 2015.
I noticed that what the control was doing was merely displaying large chunks of text which were streamed from BLOB object. I played with it for a bit and came up with this:
For this recipe, you will need:
– 1 table with BLOB field of type Memo (to hold the object in text format)
– 1 page with Code Viewer control – set Control Add-In Type = Microsoft.Dynamics.Nav.Client.CodeViewer;PublicKeyToken=31bf3856ad364e35
This code snippet:
CodeStream@1007 : InStream;
BreakpointCollection@1006 : DotNet "'Microsoft.Dynamics.Nav.Client.CodeViewerTypes, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.Client.CodeViewerTypes.BreakpointCollection";
Code@1005 : BigText;
LineNo@1000 : Integer;
CodeText@1001 : Text;
IF "BLOB Reference".HASVALUE THEN BEGIN
Code.ADDTEXT('Nothing to see, move along');
LineNo := 1;
Now this gives us nice & shiny, user-friendly display of the code.It even highlights the keywords in code, making it easier to read. It is not, unfortunately, editable – that would have been a nice coup 🙂
Having done this, I had a thought – where exactly does NAV debugger get NAV code from when it needs to display it?
The answer was pretty simple, actually – there is a BLOB field in Object Metadata table called “User AL Code”.
Just exchange the above code with this, where Type and ID are fields from Object table:
IF ObjectMetadata.GET(Type,ID) THEN BEGIN
ObjectMetadata.CALCFIELDS("User AL Code");
ObjectMetadata."User AL Code".CREATEINSTREAM(CodeStream);
LineNo := 1;
You will get this nice view of NAV code. There are two added benefits:
- you don’t actually have to have the object in question within your license to see the code: this helps nicely when you need a quick glance at such objects
- You can see what code is executed if you are unsure if old version of code may still be held by the server
And now for added bonus – you can use field “User Code” instead of “User AL Code” in the last snippet to see C# code: