Chapter 2. Architectural Patterns

Architectural Patterns are the larger building blocks of your application. They define how the data is stored in the database.

Microsoft Dynamics NAV uses the SQL Server as a database platform. Within the SQL Server, there are a large number of ways to store data. This chapter will discuss a number of ways that are best practice, which will be recognized by the experienced developers.

The members of the Architectural Patterns are the Design Patterns that typically contain field elements and pieces of business logic. Other parts of the business logic are provided by the internal API's generic containers with reusable functions.

All the patterns are described with an abstract, technical description, and with a few examples of the functional usages in the Microsoft Dynamics NAV application.

In this chapter, we will cover:

  • Singleton
  • Supplemental & Subsidiary
  • Compound
  • Rules
  • Master Data
  • Journal Template-Batch-Line
  • Entries
  • Document
  • Argument

The Singleton Pattern

Within the EARP application, we need to store information that is shared across the system for all the users. These values are unique in the application, and when changed they are valid immediately for everyone inside a company. They can be held in memory, and are only acquired from the database when changed. For this requirement, we can implement the Singleton Pattern.

Technical description

The Singleton pattern contains a table object with a specific primary key structure that is enforced by the system, allowing the table object to contain only one record. Users cannot add or remove records. When a new company is created, a record in each Singleton table is created automatically, although this is optional.

To enforce the existence of a record when it is required, each Page object that is based on the table should contain business logic to create the record, in case it does not exist yet. The reasons for the record to be missing can be that the table was a part of an update, acquired after the company was created.

The following diagram explains how to implement the Singleton Pattern:

Technical description

Since the Page objects, by default, allow users to create and delete records in tables, this should be blocked by setting the InsertAllowed and DeleteAllowed properties to No on the page.

The table object always has a field named Primary Key as a single Primary Key. This field has ID 1, and Code 10. The value of the key field is blank.

Company-Initialize

One of the oldest Codeunit objects in the Microsoft Dynamics NAV Application is Company-Initialize. This Codeunit has ID 2.

Each time a new company is created Codeunit is executed automatically, and it ensures the creation of many Singleton tables. When creating a new Singleton table, you can consider adding this to the Codeunit, although this is not mandatory.

Tip

When making changes directly in Codeunit 2, you might create possible merge conflicts. Consider using the Hooks pattern to avoid this conflict. This pattern will be discussed in Chapter 5, Coding Best Practices.

Implementations

The Singleton Pattern is used for Single Record Setup Tables and Role Center Activity Pages.

Any table that forms a functional perspective, which only requires one record, is eligible for this Pattern, such as Company Information.

Examples

In the standard Microsoft Dynamics NAV application, the examples of the usage are as follows:

Table ID

Description

79

The Company Information

98

The General Ledger Setup

242

The Source Code Setup

311

Sales & Receivables Setup

312

Purchases & Payables Setup

1313

The Mini Activities Cue

9050

The Warehouse Basic Cue

Enhancements

A possible enhancement to this pattern would be in providing the default setup rules when generating records in the database. This should be functioning as a member of the table. The function can be called from the Codeunit Company-Initialize, or from the Page UI.

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

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