Reorganizing
This commit is contained in:
parent
a4f6467d78
commit
f4886ee235
326 changed files with 4 additions and 0 deletions
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
|
|
@ -0,0 +1,100 @@
|
|||
+++
|
||||
title = "Singleton Table"
|
||||
weight = 1110
|
||||
+++
|
||||
## Singleton Table
|
||||
|
||||
_By Elly Nkya at Microsoft Development Center Copenhagen_
|
||||
|
||||
## [![ ][image0]][anchor0]
|
||||
|
||||
_
|
||||
_
|
||||
|
||||
**Problem**: The developer needs to define a single record that can contain a set of rules and behavior (optional, mandatory, or defaulting mechanisms), that apply to a functionality, and can be configured by a user.
|
||||
|
||||
****
|
||||
|
||||
**Forces**
|
||||
|
||||
* You want a central place to define the address and logo of your company (see Company Information table).
|
||||
* You want to define the no. series that should be used for your sales documents (see Sales & Receivables Setup table).
|
||||
* You want to know whether your sales documents should be archived (see Sales & Receivables Setup table).
|
||||
* You want to define the rounding accuracy your system should (see General Ledger Setup table).
|
||||
|
||||
**Solution:** Define a single record that can contain a set of rules and behavior (optional, mandatory, or defaulting mechanisms), that apply to a functionality, and can be configured by a user.
|
||||
|
||||
In a functionality that is large enough (such as sales, inventory, fixed) you may want to define a global set of rules, that are configurable by the user.
|
||||
|
||||
**Implementation**
|
||||
|
||||
**1\. Define: **Create a Setup Table with Dummy a Primary Key. Typically with type Code=10\. Then add fields to define the global rules.
|
||||
|
||||
**2\. Instantiate: **Place the instantiation code in a central place where it is guaranteed to be invoked before the functionality uses it. This is done in Codeunit 2\.
|
||||
|
||||
**3\. Enforce: **Give the user access to the record so that he can change the default setup, by creating a Card page. On the page, enforce the singleton to prevent deletion of the record or insertion of a new record
|
||||
|
||||
**4\. Use: **Access the rule in code and use it
|
||||
|
||||
****
|
||||
|
||||
**NAV Usages**
|
||||
|
||||
Rounding rules for Unit-Amounts and Amounts are implemented using the Singleton pattern.
|
||||
|
||||
**1\. Define:** The General Ledger Setup is used for this.
|
||||
|
||||
**2\. Instantiate:** In codeunit 2, the following code is invoked
|
||||
|
||||
WITH GLSetup DO
|
||||
IF NOT FINDFIRST THEN BEGIN
|
||||
INIT;
|
||||
INSERT;
|
||||
END;
|
||||
|
||||
**3\. Enforce:** On the General Ledger Setup. The following properties are setup:
|
||||
|
||||
DeleteAllowed=false,
|
||||
InsertAllowed=false
|
||||
|
||||
**4\. Use:** Access the rounding rules are used
|
||||
|
||||
...
|
||||
GLSetup.GET;
|
||||
UnitCostCurrency := ROUND(...,GLSetup."Unit-Amount Rounding Precision");
|
||||
...
|
||||
|
||||
Or if accessing the rule multiple times and performance is a consideration, use lazy instantiation:
|
||||
|
||||
...
|
||||
GetGLSetup;
|
||||
UnitCostCurrency := ROUND(...,GLSetup."Unit-Amount Rounding Precision");
|
||||
...
|
||||
|
||||
LOCAL GetGLSetup()
|
||||
IF NOT GLSetupRead THEN
|
||||
GLSetup.GET;
|
||||
GLSetupRead := TRUE;
|
||||
|
||||
**Related topics**
|
||||
|
||||
[Singleton design pattern][anchor1].
|
||||
|
||||
The **Singleton Table** has two established applications in Dynamics NAV:
|
||||
|
||||
1. [**Setup Tables**][anchor2] -- which are commonly storing user setup data in NAV,
|
||||
2. **Cue Tables** -- used to calculate values for the visual representation of Cues on the NAV role center pages.
|
||||
|
||||
YouTube Video of NAV Singleton:
|
||||
|
||||
[watch?v=aQPu s9FkYI&list=PLhZ3P LY7CqmVszuvtJLujFyHpsVN0Uw&index=13][anchor3]
|
||||
|
||||
|
||||
|
||||
[anchor0]: 5554.Singleton-Table.png
|
||||
[anchor1]: https://en.wikipedia.org/wiki/Singleton_pattern
|
||||
[anchor2]: /nav/w/designpatterns/76.setup-table
|
||||
[anchor3]: https://www.youtube.com/watch?v=aQPu-s9FkYI&list=PLhZ3P-LY7CqmVszuvtJLujFyHpsVN0U_w&index=13
|
||||
|
||||
|
||||
[image0]: 5554.Singleton-Table.png
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
|
|
@ -0,0 +1,141 @@
|
|||
+++
|
||||
title = "Cue Table"
|
||||
weight = 440
|
||||
+++
|
||||
## Cue Table
|
||||
|
||||
_By Bogdana Botez at Microsoft Development Center Copenhagen
|
||||
_
|
||||
|
||||
_[![ ][image0]][anchor0]
|
||||
_
|
||||
|
||||
Cues are the second usual application of the [**Singleton Table**][anchor1] pattern in Dynamics NAV, after [**Setup Tables**][anchor2].
|
||||
|
||||
**Context**: The user gets overview information about the business on the Dynamics NAV Role Center page.
|
||||
|
||||
Figure 1 - Cue information in Dynamics NAV shows cue information seen by the user on the **Sales Order Processor** role center.
|
||||
|
||||
[![ ][image1]][anchor3]
|
||||
|
||||
The overview information consists of summed-up numbers, calculated from business data, like for example how many sales orders are still open, how many shipments are ready to go, or partially shipped, how many documents are waiting for approval etc.
|
||||
|
||||
**Problem**: NAV stores data in tables. By definition, a table is a repetitive structure containing multiple lines, each line having a different piece of the information. But sometimes this repetitive information needs to be summed-up or otherwise synthetized, and presented as an overview.
|
||||
|
||||
**
|
||||
**
|
||||
|
||||
**Solution:** Store overview information in a singleton table.
|
||||
|
||||
****
|
||||
|
||||
There are two ways of calculating overview information in NAV.
|
||||
|
||||
1. By using a FlowField. This applies for simpler calculations, like filtered or unfiltered counts, sums etc.
|
||||
2. By writing C/AL code to perform custom calculations. Use this when:
|
||||
|
||||
* * The way to calculate the overview is too complex for flow fields, or
|
||||
* The data needs to be pulled from an external system (like Dynamics CRM, QuickBooks or any external integration).
|
||||
|
||||
**
|
||||
**
|
||||
|
||||
The implementation of Cues is already described in detail on MSDN, in [Creating and Customizing Cues][anchor4] and in [Walkthrough: Creating a Cue Based on a FlowField][anchor5].
|
||||
|
||||
**NAV Usages**
|
||||
|
||||
Table 1 - Cue tables in Dynamics NAV****shows some examples of singleton tables used for creating Cues.
|
||||
|
||||
Table ID
|
||||
|
||||
Table Name
|
||||
|
||||
1313
|
||||
|
||||
Activities Cue
|
||||
|
||||
5370
|
||||
|
||||
CRM Synch. Job Status Cue
|
||||
|
||||
9042
|
||||
|
||||
Team Member Cue
|
||||
|
||||
9050
|
||||
|
||||
Warehouse Basic Cue
|
||||
|
||||
9051
|
||||
|
||||
Warehouse WMS Cue
|
||||
|
||||
9052
|
||||
|
||||
Service Cue
|
||||
|
||||
9053
|
||||
|
||||
Sales Cue
|
||||
|
||||
9054
|
||||
|
||||
Finance Cue
|
||||
|
||||
9055
|
||||
|
||||
Purchase Cue
|
||||
|
||||
9056
|
||||
|
||||
Manufacturing Cue
|
||||
|
||||
9057
|
||||
|
||||
Job Cue
|
||||
|
||||
9058
|
||||
|
||||
Warehouse Worker WMS Cue
|
||||
|
||||
9059
|
||||
|
||||
Administration Cue
|
||||
|
||||
9060
|
||||
|
||||
SB Owner Cue
|
||||
|
||||
9061
|
||||
|
||||
RapidStart Services Cue
|
||||
|
||||
9063
|
||||
|
||||
Relationship Mgmt. Cue
|
||||
|
||||
9069
|
||||
|
||||
O365 Sales Cue
|
||||
|
||||
9070
|
||||
|
||||
Accounting Services Cue
|
||||
|
||||
Table 1 - Cue tables in Dynamics NAV
|
||||
|
||||
___
|
||||
_
|
||||
|
||||
|
||||
|
||||
[anchor0]: Cue-Table.png
|
||||
[anchor1]: /nav/w/designpatterns/151.singleton-table
|
||||
[anchor2]: /nav/w/designpatterns/76.setup-table
|
||||
[anchor3]: Cue-Table-Figure-1.JPG
|
||||
[anchor4]: https://msdn.microsoft.com/en-us/library/dn789553(v=nav.90).aspx
|
||||
[anchor5]: https://msdn.microsoft.com/en-us/library/ff477101(v=nav.90).aspx
|
||||
|
||||
|
||||
[image0]: Cue-Table.png
|
||||
[image1]: Cue-Table-Figure-1.JPG
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
|
|
@ -0,0 +1,73 @@
|
|||
+++
|
||||
title = "Setup Table"
|
||||
weight = 1070
|
||||
+++
|
||||
## Setup Table
|
||||
|
||||
_By Abhishek Ghosh, at Microsoft Development Center Copenhagen_
|
||||
|
||||
## [![ ][image0]][anchor0]
|
||||
|
||||
This is the first and most well-known of the two usual applications of the **Singleton Table** pattern in Dynamics NAV.
|
||||
|
||||
**Problem:** the developer needs to store information about the operating setup or environment in the database, in a way that can be persisted across sessions.
|
||||
|
||||
**Solution:** The information is stored in a table with one record only. The user is subsequently able to modify, but not add or delete records in the table.
|
||||
|
||||
The implementation of the pattern involves several considerations:
|
||||
|
||||
* Suffixing the table name with Setup (ex: General Ledger Setup).
|
||||
* Defining a suitable primary key
|
||||
* Creating a page where the user can view and edit a record, but not add new records or delete an existing one
|
||||
* Optionally, updating the Company - Initialize codeunit.
|
||||
|
||||
**Defining a Primary Key**
|
||||
|
||||
Since this kind of tables is a collection of several environment or setup parameters, the primary key does not refer to any business attributes for this kind of tables. However, for maintaining the integrity of the database, it is necessary to define a primary key.
|
||||
|
||||
So, the most common implementation is to have a field "Primary Key" of Code\[10\]. This is populated with a blank value when the record is inserted. This field is not added to the page, so that the user cannot be modify it later.
|
||||
|
||||
**Creating a Page**
|
||||
|
||||
The **CardPage** type is most suitable for representing this kind of tables. In addition, the **InsertAllowed** and **DeleteAllowed** properties in the page should be set to false to prevent the user from adding or deleting records in the table.
|
||||
|
||||
In the **OnOpenPage** trigger, the following code should be added to insert a record when the user opens the page for the first time, if a record does not exist already.
|
||||
|
||||
OnOpenPage()
|
||||
RESET;
|
||||
IF NOT GET THEN BEGIN
|
||||
INIT;
|
||||
INSERT;
|
||||
END;
|
||||
|
||||
The following diagram describes the flow of the program, once the user tries to access the setup information. The user opens the page. If the record containing setup information already exists, then the page opens on the existing record. Else, a new empty record is created and the page opens on it.
|
||||
|
||||
[![ ][image1]][anchor1]
|
||||
|
||||
**Company-Initialize Codeunit**
|
||||
|
||||
The Company-Initialize codeunit (codeunit 2) is executed when a new company is created. We recommended that you add records to the single-record tables in this codeunit. If some of the fields are expected to have default values, they can also be populated here.
|
||||
|
||||
**NAV Usages**
|
||||
|
||||
Several Setup tables in NAV implement this pattern. Some of those are:
|
||||
|
||||
* Table 98 General Ledger Setup
|
||||
* Table 311 Sales & Receivables Setup
|
||||
* Table 312 Purchases & Payables Setup
|
||||
* Table 313 Inventory Setup
|
||||
* Table 242 Source Code Setup
|
||||
|
||||
**Variation: **While most tables just insert a record with empty primary key in codeunit 2, table 242 ("Source Code Setup") offers an example of inserting default values into all fields of the table (method "InitSourceCodeSetup"). This practice, wherever feasible, is likely to reduce the effort during implementation.
|
||||
|
||||
**Related resources:** [Considerations on optimizing the Singleton Table, by Søren Klemmensen][anchor2].
|
||||
|
||||
|
||||
|
||||
[anchor0]: Setup-Table.png
|
||||
[anchor1]: 6675.NAVSetupTablePattern2.png
|
||||
[anchor2]: http://www.klemmensen.ca/Blog/Post/35/Initialize-Setup-Tables
|
||||
|
||||
|
||||
[image0]: Setup-Table.png
|
||||
[image1]: 6675.NAVSetupTablePattern2.png
|
||||
Loading…
Add table
Add a link
Reference in a new issue