Text fields on Dynamics NAV 2016 cues

Been a long time since last post, not because I was lazy but because there was too much to do 🙂

I had some fun trying to get Text FlowField to show on NAV 2016 Activity page.

Per NAV documentation, Cues are supposed to support Integer, Decimal and Text fields as of NAV 2015. Funny thing is, there are no examples of Text fields on standard NAV cues in 2016. Not a single one.

So when I tried to add one, I got a very useless stack image with count of 0 and text field title.

Fast forward an hour or so of trying various things.

The trick is to add the Text field OUTSIDE of CueGroup. It needs to be at the same level as CueGroup, otherwise NAV assumes it needs to show as Stack which is a bit useless.

Advertisements
Text fields on Dynamics NAV 2016 cues

SETFILTER vs. SETRANGE

NB: This is a rewritten version of earlier article.

You could write:

Record.SETFILTER(FieldName, ”””);

You should write:

Record.SETFILTER(FieldName, ‘%1’,”);

Or even better:

Record.SETRANGE(FieldName, ”);

The above is what I wrote before I went on leave.

Funnily enough, after getting back from my leave I ran into an issue that directly relates and which made me rewrite this blog post.

SETFILTER will, in most cases, be able to replicate SETRANGE functionality.

However, is there are reserved characters within the filter text these will be interpreted differently if you use:

SETFILTER(FieldName, txtFilter);

vs.

SETFILTER(FieldName, ‘%1’, txtFilter);

In first case, txtFilter will be parsed as filter text. This will cause runtime errors if txtFilter contains something like “(” character.

In second case filter will be applied without parsing it. This replicates SETRANGE functionality, or using filter ‘txtFilter’ in filtering dialog in user interface.

SETFILTER vs. SETRANGE

Viewing NAV code from RTC

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:
CodeViewer

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=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Microsoft.Dynamics.Nav.Client.CodeViewerTypes.BreakpointCollection";
Code@1005 : BigText;
LineNo@1000 : Integer;
CodeText@1001 : Text;

OnAfterGetRecord()
IF "BLOB Reference".HASVALUE THEN BEGIN
  CALCFIELDS("BLOB Reference");
  "BLOB Reference".CREATEINSTREAM(CodeStream);
  Code.READ(CodeStream);
END ELSE
  Code.ADDTEXT('Nothing to see, move along');
LineNo := 1;
CurrPage.CodeViewer.LoadCode(Code,LineNo,BreakpointCollection,TRUE);

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);
  Code.READ(CodeStream);
  LineNo := 1;
  CurrPage.CodeViewer.LoadCode(Code,LineNo,BreakpointCollection,TRUE);
END;

You will get this nice view of NAV code. There are two added benefits:

  1. 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
  2. You can see what code is executed if you are unsure if old version of code may still be held by the server

CodeViewer-Runtime

And now for added bonus – you can use field “User Code” instead of “User AL Code” in the last snippet to see C# code:

CodeViewer-CSharp

Viewing NAV code from RTC

Local and Global variables with same name – a cautionary tale

There is a function GetReport in Codeunits 82 & 92 (it is still there in NAV 2015, and has been there at least from NAV 2009) and it decides which report gets printed. You would think it is intended to be available from anywhere in NAV, but you would be wrong.

The catch is in variable SalesHeader/PurchHeader, where same name was used both for parameter of the function, as well as for a Global variable.

When function is called from CU82/92, it works fine (as it references the Global variable).

Try calling it from elsewhere, and you get <Uninitialized> on the variable in All pane. Try looking in Locals, and there it is again, but this time it contains data.

Unfortunately, the Global variable takes precedence and the parameter gets ignored….

Local and Global variables with same name – a cautionary tale

Handling Memo fields on Card pages in NAV 2013 and later

I had a need.

No, not for speed, rather for lots of text. I needed to display a lot of editable text in user-friendly way on a card page.

I looked for ready-made solutions on the web and found this post from 2012:

http://nav-magno.be/2012/05/rtc-memonote-field-sort-of/

That seemed like a good place to start,  and led to me writing this post.

For this fine recipe, you will need:

  1. One BLOB field of subtype Memo
  2. One page of type Card
  3. One variable of type Text (leave size empty) – used as container for BLOB on the page
  4. Some Text constants for various messages
  5. 3 functions described below

Add a field to the page and bind it to the text constant. Set the Multiline property to TRUE.

Call the new functions from appropriate triggers:

  • BlobOnAfterGetRec in OnAfterGetRecord(): displays the contents of the BLOB on the page
  • BlobAssistEdit in OnAssistEdit() on the field: loads BLOB contents from a file into the BLOB
  • BlobOnValidate in OnValidate() on the field: saves any edits to the Text variable to BLOB

Use FIELDNO function on the BLOB field to get intFieldNo parameter. Text variable is used for ptxtTextField.

Code is after the break. Yes, I know this will show off my bad coding habits. Use of Hungarian notation and non-standard BEGIN/END definitely does not conform to NAV standards 🙂
Continue reading “Handling Memo fields on Card pages in NAV 2013 and later”

Handling Memo fields on Card pages in NAV 2013 and later

Weird captions on Dimension-related fields in NAV2009R2

In the last 2 days I have made some interesting discoveries on how Microsoft implemented CaptionClass in NAV2009R2 RTC on Dimension fields.

It appears that the caption for page fields related to Dimensions was not using the actual caption from the page or field, even though CaptionClass property was blank.

To check for yourself, you will need an out-of-the box deployment of NAV2009R2 (build 32012) and some minor development.

Create a field in a table, related to Global Dimension 1 Code:

TableRelation = “Dimension Value”.Code WHERE (Global Dimension No.=CONST(1))

Leave CaptionClass property empty, and customize the captions on field and page to two different values. Make sure the field Code Caption on Dimension table is filled in.

Run the page. The caption on the page will be drawn from Code Caption on the Dimension table, even though CaptionClass is not used. To test this, delete Code Caption from the Dimension table. You will also need to restart NAV RTC client. Run the page again, and the captions will be empty.

This behaviour has changed somewhere between 32012 and build 37104 for NAV2009R2 – now it seems to require CaptionClass to be defined on the table field to display anything, otherwise the caption is blank.

Either way, it does not conform to expected behaviour of CaptionClass property.

Weird captions on Dimension-related fields in NAV2009R2

Fun with RUNMODAL and Classic client

Hi folks,

After 13 years in MS Dynamics NAV world, I got to think I should be sharing the (more or less) interesting things I discover in my daily work with a wider audience.

To get things started, here is a little something I discovered last week.

I was of belief that FORM.RUNMODAL ensures user has to close that FORM before continuing (same with report, page etc.)

Looking at online help, it says that too: When a form is run modally, no input (keyboard or mouse click) can occur except to objects on the modal form.

Unfortunately, this does not work like that for NAV 2009 Classic (and possibly for versions back to 4.0).

To test, try this:

Add new menu option to any button on any form. Have it call:

FORM.RUNMODAL(20);

Run NAV, navigate to that form, and click your function. Then click any menuitem on MenuSuite, and continue happily working in NAV with “MODAL” form in the background….

Luckily, RTC doesn’t have this issue (at least in 2015, haven’t tested older versions) 🙂

Fun with RUNMODAL and Classic client