The RecordRef variable in Microsoft Dynamics NAV is a very useful data type. Especially when writing generic code where you can’t predict the record type. Using the RecordRef variable can drastically reduce your code.
But sometimes you need to run a certain Page (or Report), based on the record type. To run the default lookup Page of a table, you can use 0 as the Page ID.
When you try to run a Page with a RecordRef variable instead of a Record type, you get an error message:
In most cases you will end up with some code like this:
There is a solution to avoid this kind of code! And it works with Windows Client (RTC) and Classic Client. The trick is to first put the RecordRef variable in a Variant variable, and then run the Page with the Variant:
This trick works with Pages, Reports and Forms!