Where to write customized code

While writing your own customized code for Dynamics NAV, it is important to choose where to write that code. Code can be written in different places and the application will still work as you had intended. Unfortunately, not all places are good choices. Depending on where you write your code, it may be easier or more difficult to expand or change functionality. In this section, we will give you some guidelines for choosing where to write your code.

Validating fields

When a field is filled, a special trigger runs the OnValidate trigger of the field. For a given field, you will find an OnValidate trigger on the page where the user enters the data and also on the table itself. Whenever possible, write your code on the OnValidate trigger of the table.

A field can be shown on multiple pages. If you choose to validate the field on the page, you will have to replicate your code in all the pages where the field is shown. This will make your code difficult to maintain.

Batch jobs

Batch jobs are written using a Report object. Typically, batch jobs are not to be done for all the records on a table, but for a set of them. In most cases, it is the user who selects what set of data has to be processed. The Report objects are the ones that best suit these requirements, since they have an interface that allows the users to select options or filter the data.

Batch jobs

The previous screenshot is an example of a Batch Post Sales Order report. It is used to post multiple sales orders at once. As we can see in the screenshot, there is an Options tab, and a Sales Order tab that allows the users to filter the data.

In this section, we saw where to write customized code. Besides following the guidelines given in this book, there are other options that will help you choose where to write your code. When you need to write a new functionality, you can search for a similar functionality on the standard application and try to mimic the structure.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.66