This commit is contained in:
TheDoubleH 2022-02-11 17:30:04 +00:00
parent de09820554
commit e4f08bf9a7
187 changed files with 6620 additions and 6342 deletions

View file

@ -6,16 +6,16 @@
<link rel=alternate type=application/rss+xml href=/navpatterns/1-patterns/singleton/singleton-table/index.xml title="AL Guidelines">
<meta name=description content>
<title>Singleton Table :: AL Guidelines</title>
<link href=/css/nucleus.css?1644506471 rel=stylesheet>
<link href=/css/fontawesome-all.min.css?1644506471 rel=stylesheet>
<link href=/css/featherlight.min.css?1644506471 rel=stylesheet>
<link href=/css/perfect-scrollbar.min.css?1644506471 rel=stylesheet>
<link href=/css/auto-complete.css?1644506471 rel=stylesheet>
<link href=/css/theme.css?1644506471 rel=stylesheet>
<link href=/css/theme-blue.css?1644506471 rel=stylesheet>
<link href=/css/variant.css?1644506471 rel=stylesheet>
<link href=/css/print.css?1644506471 rel=stylesheet media=print>
<script src=/js/jquery.min.js?1644506471></script>
<link href=/css/nucleus.css?1644600601 rel=stylesheet>
<link href=/css/fontawesome-all.min.css?1644600601 rel=stylesheet>
<link href=/css/featherlight.min.css?1644600601 rel=stylesheet>
<link href=/css/perfect-scrollbar.min.css?1644600601 rel=stylesheet>
<link href=/css/auto-complete.css?1644600601 rel=stylesheet>
<link href=/css/theme.css?1644600601 rel=stylesheet>
<link href=/css/theme-blue.css?1644600601 rel=stylesheet>
<link href=/css/variant.css?1644600601 rel=stylesheet>
<link href=/css/print.css?1644600601 rel=stylesheet media=print>
<script src=/js/jquery.min.js?1644600601></script>
<style>:root #header+#content>#left>#rlblock_left{display:none!important}</style>
</head>
<body data-url=/navpatterns/1-patterns/singleton/singleton-table/>
@ -33,9 +33,9 @@ ALGuidelines.Dev
<input data-search-input id=search-by type=search placeholder=Search...>
<span data-search-clear><i class="fas fa-times"></i></span>
</div>
<script src=/js/lunr.min.js?1644506471></script>
<script src=/js/auto-complete.js?1644506471></script>
<script src=/js/search.js?1644506471></script>
<script src=/js/lunr.min.js?1644600601></script>
<script src=/js/auto-complete.js?1644600601></script>
<script src=/js/search.js?1644600601></script>
</div>
<div class=highlightable>
<ul class=topics>
@ -251,7 +251,6 @@ ALGuidelines.Dev
<nav id=TableOfContents>
<ul>
<li><a href=#singleton-table>Singleton Table</a></li>
<li><a href=#-image0anchor0><a href=5554.Singleton-Table.png><img src=5554.Singleton-Table.png alt=" "></a></a></li>
</ul>
</nav>
</div>
@ -263,11 +262,8 @@ ALGuidelines.Dev
<h1>Singleton Table</h1>
<h2 id=singleton-table>Singleton Table</h2>
<p><em>By Elly Nkya at Microsoft Development Center Copenhagen</em></p>
<h2 id=-image0anchor0><a href=5554.Singleton-Table.png><img src=5554.Singleton-Table.png alt=" "></a></h2>
<p>_<br>
_</p>
<p><a href=5554.Singleton-Table.png><img src=5554.Singleton-Table.png alt=" "></a></p>
<p><strong>Problem</strong>: 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.</p>
<hr>
<p><strong>Forces</strong></p>
<ul>
<li>You want a central place to define the address and logo of your company (see Company Information table).</li>
@ -282,43 +278,38 @@ _</p>
<p><strong>2. Instantiate:</strong> 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.</p>
<p><strong>3. Enforce:</strong> 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</p>
<p><strong>4. Use:</strong> Access the rule in code and use it</p>
<hr>
<p><strong>NAV Usages</strong></p>
<p>Rounding rules for Unit-Amounts and Amounts are implemented using the Singleton pattern.</p>
<p><strong>1. Define:</strong> The General Ledger Setup is used for this.</p>
<p><strong>2. Instantiate:</strong> In codeunit 2, the following code is invoked</p>
<pre><code>WITH GLSetup DO
IF NOT FINDFIRST THEN BEGIN
INIT;
INSERT;
END;
</code></pre>
<p><strong>3. Enforce:</strong> On the General Ledger Setup. The following properties are setup:</p>
<pre><code>DeleteAllowed=false,
InsertAllowed=false
</code></pre>
<p><strong>4. Use:</strong> Access the rounding rules are used</p>
<pre><code>...
GLSetup.GET;
UnitCostCurrency := ROUND(...,GLSetup.&quot;Unit-Amount Rounding Precision&quot;);
...
</code></pre>
<p>Or if accessing the rule multiple times and performance is a consideration, use lazy instantiation:</p>
<pre><code>...
GetGLSetup;
UnitCostCurrency := ROUND(...,GLSetup.&quot;Unit-Amount Rounding Precision&quot;);
...
LOCAL GetGLSetup()
IF NOT GLSetupRead THEN
GLSetup.GET;
GLSetupRead := TRUE;
</code></pre>
<p><strong>Related topics</strong></p>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al><span style=color:#66d9ef>WITH</span> GLSetup <span style=color:#66d9ef>DO</span>
<span style=color:#66d9ef>IF</span> <span style=color:#f92672>NOT</span> FINDFIRST <span style=color:#66d9ef>THEN</span> <span style=color:#66d9ef>BEGIN</span>
INIT;
INSERT;
<span style=color:#66d9ef>END</span>;
</code></pre></div><p><strong>3. Enforce:</strong> On the General Ledger Setup. The following properties are setup:</p>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al> DeleteAllowed=false,
InsertAllowed=false
</code></pre></div><p><strong>4. Use:</strong> Access the rounding rules are used</p>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al><span style=color:#f92672>...
</span><span style=color:#f92672></span>GLSetup<span style=color:#f92672>.</span>GET;
UnitCostCurrency <span style=color:#f92672>:=</span> ROUND<span style=color:#f92672>(...</span>,GLSetup<span style=color:#f92672>.</span>&#34;Unit-Amount Rounding Precision&#34;<span style=color:#f92672>)</span>;
<span style=color:#f92672>...
</span></code></pre></div><p>Or if accessing the rule multiple times and performance is a consideration, use lazy instantiation:</p>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al><span style=color:#f92672>...
</span><span style=color:#f92672></span>GetGLSetup;
UnitCostCurrency <span style=color:#f92672>:=</span> ROUND<span style=color:#f92672>(...</span>,GLSetup<span style=color:#f92672>.</span>&#34;Unit-Amount Rounding Precision&#34;<span style=color:#f92672>)</span>;
<span style=color:#f92672>...
</span><span style=color:#f92672>
</span><span style=color:#f92672></span><span style=color:#66d9ef>LOCAL</span> GetGLSetup<span style=color:#f92672>()
</span><span style=color:#f92672></span><span style=color:#66d9ef>IF</span> <span style=color:#f92672>NOT</span> GLSetupRead <span style=color:#66d9ef>THEN</span>
GLSetup<span style=color:#f92672>.</span>GET;
GLSetupRead <span style=color:#f92672>:=</span> TRUE;
</code></pre></div><p><strong>Related topics</strong></p>
<p><a href=https://en.wikipedia.org/wiki/Singleton_pattern>Singleton design pattern</a>.</p>
<p>The <strong>Singleton Table</strong> has two established applications in Dynamics NAV:</p>
<ol>
<li><a href=/nav/w/designpatterns/76.setup-table><strong>Setup Tables</strong></a> &ndash; which are commonly storing user setup data in NAV,</li>
<li><a href=/navpatterns/1-patterns/singleton/singleton-table/setup-table/><strong>Setup Tables</strong></a> &ndash; which are commonly storing user setup data in NAV,</li>
<li><strong>Cue Tables</strong> &ndash; used to calculate values for the visual representation of Cues on the NAV role center pages.</li>
</ol>
<p>YouTube Video of NAV Singleton:</p>
@ -337,12 +328,12 @@ GLSetupRead := TRUE;
<div style=left:-1000px;overflow:scroll;position:absolute;top:-1000px;border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px>
<div style=border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px></div>
</div>
<script src=/js/clipboard.min.js?1644506471></script>
<script src=/js/perfect-scrollbar.min.js?1644506471></script>
<script src=/js/perfect-scrollbar.jquery.min.js?1644506471></script>
<script src=/js/jquery.svg.pan.zoom.js?1644506471></script>
<script src=/js/featherlight.min.js?1644506471></script>
<script src=/js/modernizr.custom-3.6.0.js?1644506471></script>
<script src=/js/relearn.js?1644506471></script>
<script src=/js/clipboard.min.js?1644600601></script>
<script src=/js/perfect-scrollbar.min.js?1644600601></script>
<script src=/js/perfect-scrollbar.jquery.min.js?1644600601></script>
<script src=/js/jquery.svg.pan.zoom.js?1644600601></script>
<script src=/js/featherlight.min.js?1644600601></script>
<script src=/js/modernizr.custom-3.6.0.js?1644600601></script>
<script src=/js/relearn.js?1644600601></script>
</body>
</html>