deploy: 615864e950
This commit is contained in:
parent
68deff1d24
commit
7686ef4d97
199 changed files with 2440 additions and 897 deletions
|
|
@ -1,4 +1,58 @@
|
|||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>alguidelines.dev - Business Central Design Patterns – Design Patterns</title><link>https://alguidelines.dev/docs/patterns/</link><description>Recent content in Design Patterns on alguidelines.dev - Business Central Design Patterns</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><atom:link href="https://alguidelines.dev/docs/patterns/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs: Event Bridge</title><link>https://alguidelines.dev/docs/patterns/event-bridge-pattern/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/docs/patterns/event-bridge-pattern/</guid><description>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>alguidelines.dev - Business Central Design Patterns – Design Patterns</title><link>https://alguidelines.dev/docs/patterns/</link><description>Recent content in Design Patterns on alguidelines.dev - Business Central Design Patterns</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><atom:link href="https://alguidelines.dev/docs/patterns/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs: Delegate API Operation</title><link>https://alguidelines.dev/docs/patterns/api-delegate-operation/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/docs/patterns/api-delegate-operation/</guid><description>
|
||||
<p><em>Created by Arend-Jan Kauffmann, Described by Arend-Jan Kauffmann</em></p>
|
||||
<h2 id="abstract">Abstract</h2>
|
||||
<p>The goal of this pattern is to delegate data operations from the API page to a codeunit. The codeunit can implement its own logic for inserting, modifying or deleting data.</p>
|
||||
<h2 id="context">Context</h2>
|
||||
<p>API pages implement a specific pattern for insert, modify and delete operations. An API page uses delayed insert behavior, which means that all fields will be validated before the record is inserted or modified.
|
||||
This is different from the standard behavior on a UI card page, where a record is first inserted, followed by a modify when field values are updated.</p>
|
||||
<h2 id="problem">Problem</h2>
|
||||
<p>The standard behavior can result in a number of challenges:</p>
|
||||
<ul>
|
||||
<li>Code behind the OnValidate triggers and its event subscribers may expect that a record already exists when a field is being validated.</li>
|
||||
<li>Usage of temporary buffer tables can become really complex when fully handled from the API page.</li>
|
||||
<li>Applying default data to records before they are created does not work well with delayed inserts.</li>
|
||||
</ul>
|
||||
<h2 id="description">Description</h2>
|
||||
<p>To mitigate these problems, we can delegate the data operation to a codeunit while canceling the data operation inside the API page.</p>
|
||||
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-al" data-lang="al"><span style="color:#204a87;font-weight:bold">codeunit</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">50000</span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Item API Operations&#34;<span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"></span>{<span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">internal</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">procedure</span><span style="color:#f8f8f8;text-decoration:underline"> </span>InsertItem<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">var</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Item<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Record</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Item<span style="color:#ce5c00;font-weight:bold">)
|
||||
</span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#204a87;font-weight:bold">begin</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">end</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">internal</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">procedure</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ModifyItem<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">var</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Item<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Record</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Item<span style="color:#ce5c00;font-weight:bold">)
|
||||
</span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#204a87;font-weight:bold">begin</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">end</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">internal</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">procedure</span><span style="color:#f8f8f8;text-decoration:underline"> </span>DeleteItem<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">var</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Item<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Record</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Item<span style="color:#ce5c00;font-weight:bold">)
|
||||
</span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#204a87;font-weight:bold">begin</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">end</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"></span>}<span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span></code></pre></div><p>It is important that the record parameter is updated with the final result. This allows the API page to return the result of the API operation to the caller.</p>
|
||||
<p>The API page implements this in the page triggers as follows:</p>
|
||||
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-al" data-lang="al"><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">var</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemAPIOperations<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Codeunit</span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Item API Operations&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">trigger</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OnInsertRecord<span style="color:#ce5c00;font-weight:bold">(</span>BelowxRec<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Boolean</span><span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Boolean</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">begin</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemAPIOperations<span style="color:#ce5c00;font-weight:bold">.</span>InsertItem<span style="color:#ce5c00;font-weight:bold">(</span>Rec<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">exit</span><span style="color:#ce5c00;font-weight:bold">(</span>false<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">end</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">trigger</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OnModifyRecord<span style="color:#ce5c00;font-weight:bold">()</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Boolean</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">begin</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemAPIOperations<span style="color:#ce5c00;font-weight:bold">.</span>ModifyItem<span style="color:#ce5c00;font-weight:bold">(</span>Rec<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">exit</span><span style="color:#ce5c00;font-weight:bold">(</span>false<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">end</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">trigger</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OnDeleteRecord<span style="color:#ce5c00;font-weight:bold">()</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Boolean</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">begin</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemAPIOperations<span style="color:#ce5c00;font-weight:bold">.</span>DeleteItem<span style="color:#ce5c00;font-weight:bold">(</span>Rec<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">exit</span><span style="color:#ce5c00;font-weight:bold">(</span>false<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">end</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span></code></pre></div><p>The triggers must return false in order to cancel the operation in the page.</p>
|
||||
<h2 id="benefits">Benefits</h2>
|
||||
<p>Inside the functions in the codeunit you have full control over the steps that are performed for the specific operation.</p></description></item><item><title>Docs: Event Bridge</title><link>https://alguidelines.dev/docs/patterns/event-bridge-pattern/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/docs/patterns/event-bridge-pattern/</guid><description>
|
||||
<p><em>Created by waldo &amp; Arend-Jan Kauffmann, Described by waldo</em></p>
|
||||
<h2 id="abstract">Abstract</h2>
|
||||
<p>In the world of interfaces, it is important to preserve (certain) events over multiple implementation of the interface.</p>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue