Dynamics NAV: open the form associated to an entity

Frequently I'm involved on code-reviewing and optimization operations with customer's Dynamics NAV databases and, when I write code together with other developers, I see always that they access the Object Designer tool in order to remember what's the right form to call for displaying data related to a table (a Dynamics NAV entity).

For example, if you make filters on the Customer table and you want to display the filtered data on a form, 99,9% of the times I see that a developer does the following:

//We want to display all the Customers with a name that starts with 'M'
Customer.SETFILTER(Customer.Name,'M*');
FORM.RUNMODAL(22,Customer);

or

Customer.SETFILTER(Customer.Name,'M*');
FORM.RUNMODAL(FORM::"Customer List",Customer);

Many of the times he use the NAV Object Designer tool in order to remember the object ID (22) of the Customer List form... what a stress...

With Dynamics NAV there's a little and useful secret: if you pass to FORM.RUNMODAL (or FORM.RUN) the form Number = 0 and the Record to be displayed, the system is so intelligent to automatically retrieve the associated form (from the table definition) that must be opened.

If you write something like:

Customer.SETFILTER(Customer.Name,'M*');
FORM.RUNMODAL(0,Customer);

magically the Customer List form will be opened.

It's more quick to write, isn't it?

Print | posted on Wednesday, December 27, 2006 2:38 PM

Comments on this post

No comments posted yet.

Your comment:

 (will show your gravatar)
 
Please add 7 and 8 and type the answer here: