Before I start, I must say I first read about this on the following Kauffmann’s blog entry. So all kudos to him When I read it I found it really interesting and used it on some of the tools we use internally. So this post will be pretty much my experience with what Kauffmann knowledge
Having said that, let’s get to it!
The RecordRef variables are, for many of the developers within the Dynamics NAV community, unknown.
The number of times on which this kind of variables is useful is very limited, and therefore it does not promote its usage or knowledge.
In this post I do not seek to describe them, or how they are used. I might save this for a future entry
Recently I found myself needing to execute a page whose ID was dynamic, and the table was dynamic as well.
The page was a list of tables inside of the system and with the number of records in each one of them. And I needed to go to the page related to that table when clicking on the number showing its records (values).
Evidently my first idea was to use a RecordRef variable for this part, and as a page number use the 0 value. This way it would use the related page to the table. The result of this was an error:
And so I started looking for ways to do this online and came across the Kauffmann blog entry I mentioned at the begining.
So, how do we do this?
Well, simple. The PAGE.RUN will not accept as a parameter for the record parameter a variable with the type “RecordRef”. But it will accept a “Variant” type variable.
So what we must do somehow is pass the info of the RecordRef variable to the Variant and use the Variant when calling the page using PAGE.RUN.
To do so we can use the following code:
RecRef.OPEN(ID); // ID = Table Number VarRecRef := RecRef; // Variant := RecordRef
And now all that’s left is executing the page.
So an example with all the code would be
RecRef.OPEN(27); // ID = Table Number | 27 = Item Table VarRecRef := RecRef; // Variant := RecordRef PAGE.RUN(0,VarRecRef); // This runs the Item List Page
Of course the same behaviour can be expected when using a report.
And that’s it!