deploy: 81ffc9da10
This commit is contained in:
parent
158b902b20
commit
cb4e8e2194
131 changed files with 3191 additions and 3076 deletions
|
|
@ -2,19 +2,19 @@
|
|||
<head>
|
||||
<meta charset=utf-8>
|
||||
<meta name=viewport content="width=device-width,initial-scale=1">
|
||||
<meta name=generator content="Hugo 0.89.0">
|
||||
<meta name=generator content="Hugo 0.89.1">
|
||||
<meta name=description content>
|
||||
<title>Currently Active Record :: BC AL Help</title>
|
||||
<link href=/css/nucleus.css?1636104707 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1636104707 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1636104707 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1636104707 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1636104707 rel=stylesheet>
|
||||
<link href=/css/theme.css?1636104707 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1636104707 rel=stylesheet>
|
||||
<link href=/css/variant.css?1636104707 rel=stylesheet>
|
||||
<link href=/css/print.css?1636104707 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1636104707></script>
|
||||
<link href=/css/nucleus.css?1636386789 rel=stylesheet>
|
||||
<link href=/css/fontawesome-all.min.css?1636386789 rel=stylesheet>
|
||||
<link href=/css/featherlight.min.css?1636386789 rel=stylesheet>
|
||||
<link href=/css/perfect-scrollbar.min.css?1636386789 rel=stylesheet>
|
||||
<link href=/css/auto-complete.css?1636386789 rel=stylesheet>
|
||||
<link href=/css/theme.css?1636386789 rel=stylesheet>
|
||||
<link href=/css/theme-blue.css?1636386789 rel=stylesheet>
|
||||
<link href=/css/variant.css?1636386789 rel=stylesheet>
|
||||
<link href=/css/print.css?1636386789 rel=stylesheet media=print>
|
||||
<script src=/js/jquery.min.js?1636386789></script>
|
||||
<style>:root #header+#content>#left>#rlblock_left{display:none!important}</style>
|
||||
</head>
|
||||
<body data-url=/navpatterns/1-patterns/currently-active-record/>
|
||||
|
|
@ -32,9 +32,9 @@ BC AL Help . 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?1636104707></script>
|
||||
<script src=/js/auto-complete.js?1636104707></script>
|
||||
<script src=/js/search.js?1636104707></script>
|
||||
<script src=/js/lunr.min.js?1636386789></script>
|
||||
<script src=/js/auto-complete.js?1636386789></script>
|
||||
<script src=/js/search.js?1636386789></script>
|
||||
</div>
|
||||
<div class=highlightable>
|
||||
<ul class=topics>
|
||||
|
|
@ -236,10 +236,18 @@ BC AL Help . dev
|
|||
A side effect is reduced and simplified code, increased performance and a more scalable solution that is almost independent of the amount of records in the table.</p>
|
||||
<h2 id=description>Description</h2>
|
||||
<p>There is no way in NAV to get a set of records from the database, which all have the newest starting date, that is less than or equal to today’s date. Having an ending date on the record will help, but it introduces some other problems. In Dynamics NAV this is normally done by reading too many records, either at the SQL Server level or in the middle tier and throw away the ones you do not need. That is a waste of resources:</p>
|
||||
<p>< –[if supportLists]–>* < –[endif]–>The SQL Server is reading too many records</p>
|
||||
<p>< –[if supportLists]–>* < –[endif]–>There would be too much data sent over the network.<br>
|
||||
<ul>
|
||||
<li>
|
||||
<p>The SQL Server is reading too many records</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>There would be too much data sent over the network.<br>
|
||||
(If the SQL Server and the NAV Service tier are on different machines.)</p>
|
||||
<p>< –[if supportLists]–>* < –[endif]–>The NAV Service Tier receives and throws away data.</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>The NAV Service Tier receives and throws away data.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<h3 id=ending-date-problem>Ending Date Problem</h3>
|
||||
<p>Ending Date may introduce some problems of its own.</p>
|
||||
<p>If your design requires to have one and only one active record per key in a dataset, then Ending Date introduces the possibility for overlapping or holes in the timeline.<br>
|
||||
|
|
@ -250,21 +258,20 @@ If you add a record in between you will have to update both the before and the a
|
|||
<p>Use the pattern whenever you read a set of data containing a Starting Date and you need to implement a loop to throw away unwanted records. An example could be Codeunit 7000 “Sales Price Calc. Mgt.”. In this codeunit there are many loop constructs to find prices and discounts.</p>
|
||||
<h2 id=usage>Usage</h2>
|
||||
<p>In the following example, we have a fictive table containing: Code, Starting Date and Price. The Primary Key consist of Code, Starting Date. The Database is the Demo Database, and the Company is Cronus.</p>
|
||||
<p>< –[if supportLineBreakNewLine]–><a href=6545.Table.png><img src=6545.Table.png alt=" "></a><br>
|
||||
< –[endif]–></p>
|
||||
<p><a href=6545.Table.png><img src=6545.Table.png alt=" "></a></p>
|
||||
<h3 id=1-create-the-view>1. Create the view</h3>
|
||||
<p>You will need to create the view before you define the Table Object.<br>
|
||||
You will need to create a view for every company in the database.</p>
|
||||
<p>CREATE VIEW [dbo].[CRONUS$PriceView]<br>
|
||||
AS<br>
|
||||
SELECT [Code], [Starting Date], [Price]<br>
|
||||
FROM dbo.[CRONUS$Price] AS A<br>
|
||||
WHERE [Starting Date] =<br>
|
||||
(SELECT MAX([Starting Date])<br>
|
||||
FROM dbo.[CRONUS$Price] AS B<br>
|
||||
WHERE B.[Code] = A.[Code] AND<br>
|
||||
B.[Starting Date] <= GETDATE())</p>
|
||||
<p>Test the view to ensure that you get the correct result. It is much easier to test now than later.</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-sql data-lang=sql> <span style=color:#66d9ef>CREATE</span> <span style=color:#66d9ef>VIEW</span> [dbo].[CRONUS$PriceView]
|
||||
<span style=color:#66d9ef>AS</span>
|
||||
<span style=color:#66d9ef>SELECT</span> [Code], [Starting Date], [Price]
|
||||
<span style=color:#66d9ef>FROM</span> dbo.[CRONUS$Price] <span style=color:#66d9ef>AS</span> A
|
||||
<span style=color:#66d9ef>WHERE</span> [Starting Date] <span style=color:#f92672>=</span>
|
||||
(<span style=color:#66d9ef>SELECT</span> <span style=color:#66d9ef>MAX</span>([Starting Date])
|
||||
<span style=color:#66d9ef>FROM</span> dbo.[CRONUS$Price] <span style=color:#66d9ef>AS</span> B
|
||||
<span style=color:#66d9ef>WHERE</span> B.[Code] <span style=color:#f92672>=</span> A.[Code] <span style=color:#66d9ef>AND</span>
|
||||
B.[Starting Date] <span style=color:#f92672><=</span> GETDATE())
|
||||
</code></pre></div><p>Test the view to ensure that you get the correct result. It is much easier to test now than later.</p>
|
||||
<h3 id=2-create-the-table-object>2. Create the Table object</h3>
|
||||
<p>Remember to set the link table property before you save it.</p>
|
||||
<h3 id=3-implement-the-code>3. Implement the code</h3>
|
||||
|
|
@ -272,42 +279,44 @@ B.[Starting Date] <= GETDATE())</p>
|
|||
<h3 id=4-create-a-deployment-codeunit>4. Create a deployment codeunit</h3>
|
||||
<p>Create a SQL Deployment codeunit to manage your views.<br>
|
||||
The codeunit needs to Create or Alter the views for all companies.<br>
|
||||
To see an example of how to talk to SQL Server using .NET see Waldo’s blog here:<br>
|
||||
<a href=http://dynamicsuser.net/blogs/waldo/archive/2011/07/19/net-interop-calling-stored-procedures-on-sql-server-example-1.aspx>http://dynamicsuser.net/blogs/waldo/archive/2011/07/19/net-interop-calling-stored-procedures-on-sql-server-example-1.aspx</a><br>
|
||||
< –[if supportLineBreakNewLine]–><br>
|
||||
< –[endif]–></p>
|
||||
To see an example of how to talk to SQL Server using .NET see waldo’s blog here:<br>
|
||||
<a href=http://dynamicsuser.net/blogs/waldo/archive/2011/07/19/net-interop-calling-stored-procedures-on-sql-server-example-1.aspx>http://dynamicsuser.net/blogs/waldo/archive/2011/07/19/net-interop-calling-stored-procedures-on-sql-server-example-1.aspx</a></p>
|
||||
<h3 id=5-deployment>5. Deployment</h3>
|
||||
<p>You need to deploy in three steps:</p>
|
||||
<p>< –[if supportLists]–>1. < –[endif]–>Delete the table objects referencing the views</p>
|
||||
<p>< –[if supportLists]–>2. < –[endif]–>Deploy and run the deployment codeunit</p>
|
||||
<p>< –[if supportLists]–>3. < –[endif]–>Deploy the new table objects that reference the views</p>
|
||||
<ol>
|
||||
<li>Delete the table objects referencing the views</li>
|
||||
<li>Deploy and run the deployment codeunit</li>
|
||||
<li>Deploy the new table objects that reference the views</li>
|
||||
</ol>
|
||||
<h3 id=general-precaution>General precaution</h3>
|
||||
<p>If you later want to change the view, you need to follow these rules:</p>
|
||||
<p>< –[if supportLists]–>* < –[endif]–>If you add columns, you need to add them to the view first and then add them to the Table Object.</p>
|
||||
<p>< –[if supportLists]–>* < –[endif]–>If you want to remove columns from the view, you need to delete the Table Object, then change the view and last recreate the Table Object without the new columns.</p>
|
||||
<p>* If you add columns, you need to add them to the view first and then add them to the Table Object.
|
||||
* If you want to remove columns from the view, you need to delete the Table Object, then change the view and last recreate the Table Object without the new columns.</p>
|
||||
<h3 id=code-example-that-accomplish-the-same-but-without-using-the-pattern>Code example that accomplish the same but without using the pattern</h3>
|
||||
<p>This following example will give you the same result but the performance will deteriorate as time goes by and you get more and more old data.</p>
|
||||
<p>Price.SETCURRENTKEY(Code,“Starting Date”);</p>
|
||||
<p>Price.SETFILTER(“Starting Date”,'..%1', TODAY</p>
|
||||
<p>IF Price.FINDSET THEN BEGIN<br>
|
||||
REPEAT</p>
|
||||
<p>Price.SETRANGE(Code, Price.Code);</p>
|
||||
<p>Price.FINDLAST;</p>
|
||||
<p>Price.SETRANGE(Code);</p>
|
||||
<p>PriceTemp := Price;</p>
|
||||
<p>PriceTemp.INSERT;</p>
|
||||
<p>UNTIL Price.NEXT = 0;</p>
|
||||
<p>END;<br>
|
||||
// PriceTemp will contain the Prices</p>
|
||||
<h3 id=comparison>Comparison</h3>
|
||||
<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>Price<span style=color:#f92672>.</span>SETCURRENTKEY<span style=color:#f92672>(</span><span style=color:#66d9ef>Code</span>,"Starting Date"<span style=color:#f92672>)</span>;
|
||||
Price<span style=color:#f92672>.</span>SETFILTER<span style=color:#f92672>(</span>"Starting Date",<span style=color:#e6db74>'..%1'</span>, TODAY
|
||||
<span style=color:#66d9ef>IF</span> Price<span style=color:#f92672>.</span>FINDSET <span style=color:#66d9ef>THEN</span> <span style=color:#66d9ef>BEGIN</span>
|
||||
<span style=color:#66d9ef>REPEAT</span>
|
||||
Price<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span><span style=color:#66d9ef>Code</span>, Price<span style=color:#f92672>.</span><span style=color:#66d9ef>Code</span><span style=color:#f92672>)</span>;
|
||||
Price<span style=color:#f92672>.</span>FINDLAST;
|
||||
Price<span style=color:#f92672>.</span>SETRANGE<span style=color:#f92672>(</span><span style=color:#66d9ef>Code</span><span style=color:#f92672>)</span>;
|
||||
PriceTemp <span style=color:#f92672>:=</span> Price;
|
||||
PriceTemp<span style=color:#f92672>.</span>INSERT;
|
||||
<span style=color:#66d9ef>UNTIL</span> Price<span style=color:#f92672>.</span>NEXT = <span style=color:#ae81ff>0</span>;
|
||||
<span style=color:#66d9ef>END</span>;
|
||||
<span style=color:#75715e>// PriceTemp will contain the Prices
|
||||
</span></code></pre></div><h3 id=comparison>Comparison</h3>
|
||||
<p>The above NAV example is for a very simple date controlled solution and is provided to give an idea of what the pattern changes seen from a NAV development point of view. But consider the following:</p>
|
||||
<p>< –[if supportLists]–>* < –[endif]–>The table has a more complex key.<br>
|
||||
This will require setting and clearing more filters</p>
|
||||
<p>< –[if supportLists]–>* < –[endif]–>You need to read from more than one table.<br>
|
||||
<ul>
|
||||
<li>The table has a more complex key.<br>
|
||||
This will require setting and clearing more filters</li>
|
||||
<li>You need to read from more than one table.<br>
|
||||
Say you need to apply discount from a separate table.<br>
|
||||
This may give several lines in PriceTemp.</p>
|
||||
<p>< –[if supportLists]–>* < –[endif]–>If the Code field is controlled by a Type field.<br>
|
||||
The Code field reference keys in different tables</p>
|
||||
This may give several lines in PriceTemp.</li>
|
||||
<li>If the Code field is controlled by a Type field.<br>
|
||||
The Code field reference keys in different tables</li>
|
||||
</ul>
|
||||
<p>All three examples above can be implemented directly in the view. By using the pattern, it will still only require a single line of NAV code.</p>
|
||||
<p>Using the pattern will only issue one SQL call and thereby one trip to the server.<br>
|
||||
The NAV Example will require an unknown number of SQL calls and thereby an unknown number of trips to the server. The number of SQL calls is dependent on the number of distinct Code values.<br>
|
||||
|
|
@ -333,12 +342,12 @@ The Pattern makes a scalable solution with a predictable performance. The perfor
|
|||
<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?1636104707></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1636104707></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1636104707></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1636104707></script>
|
||||
<script src=/js/featherlight.min.js?1636104707></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1636104707></script>
|
||||
<script src=/js/relearn.js?1636104707></script>
|
||||
<script src=/js/clipboard.min.js?1636386789></script>
|
||||
<script src=/js/perfect-scrollbar.min.js?1636386789></script>
|
||||
<script src=/js/perfect-scrollbar.jquery.min.js?1636386789></script>
|
||||
<script src=/js/jquery.svg.pan.zoom.js?1636386789></script>
|
||||
<script src=/js/featherlight.min.js?1636386789></script>
|
||||
<script src=/js/modernizr.custom-3.6.0.js?1636386789></script>
|
||||
<script src=/js/relearn.js?1636386789></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue