deploy: 7f492b2c47
This commit is contained in:
parent
7686ef4d97
commit
7006c9a415
200 changed files with 2468 additions and 1081 deletions
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
@ -68,6 +68,25 @@
|
|||
</div>
|
||||
<div>
|
||||
<article class="article-teaser article-type-docs">
|
||||
<h3><a href=/docs/patterns/api-register-fieldset/>API Register Fieldset</a></h3>
|
||||
<p></p>
|
||||
<header class=article-meta>
|
||||
<div class="taxonomy taxonomy-terms-article taxo-tags">
|
||||
<h5 class=taxonomy-title>Tags:</h5>
|
||||
<ul class=taxonomy-terms>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/al/ data-taxonomy-term=al><span class=taxonomy-label>AL</span></a></li>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/api/ data-taxonomy-term=api><span class=taxonomy-label>API</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="taxonomy taxonomy-terms-article taxo-categories">
|
||||
<h5 class=taxonomy-title>Categories:</h5>
|
||||
<ul class=taxonomy-terms>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/categories/pattern/ data-taxonomy-term=pattern><span class=taxonomy-label>Pattern</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</header>
|
||||
</article>
|
||||
<article class="article-teaser article-type-docs">
|
||||
<h3><a href=/docs/bestpractices/begin-as-an-afterword/>begin as an afterword</a></h3>
|
||||
<p></p>
|
||||
<header class=article-meta>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,90 @@
|
|||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>alguidelines.dev - Business Central Design Patterns – AL</title><link>https://alguidelines.dev/tags/al/</link><description>Recent content in AL on alguidelines.dev - Business Central Design Patterns</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><atom:link href="https://alguidelines.dev/tags/al/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs: begin as an afterword</title><link>https://alguidelines.dev/docs/bestpractices/begin-as-an-afterword/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/docs/bestpractices/begin-as-an-afterword/</guid><description>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>alguidelines.dev - Business Central Design Patterns – AL</title><link>https://alguidelines.dev/tags/al/</link><description>Recent content in AL on alguidelines.dev - Business Central Design Patterns</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><atom:link href="https://alguidelines.dev/tags/al/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs: API Register Fieldset</title><link>https://alguidelines.dev/docs/patterns/api-register-fieldset/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/docs/patterns/api-register-fieldset/</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 register the fields that are part of the request body of an API call.</p>
|
||||
<h2 id="context">Context</h2>
|
||||
<p>A request to an API page to insert or modify a record requires a JSON body with the fields and values. It is not required to specify all fields that are exposed by the API page. Only those fields that are specified in the JSON body will be validated with a value. A call to insert a record (http POST) will leave the unspecified fields at their default value. A call to modify a record (http PATCH) will only update the specified fields and leave the other fields to their current value.</p>
|
||||
<h2 id="problem">Problem</h2>
|
||||
<p>The standard behavior can result in a number of challenges:</p>
|
||||
<ul>
|
||||
<li>It&rsquo;s not possible to implement mandatory fields. Especially for fields with an initial value like integers, decimals and booleans the code doesn&rsquo;t know if they are their initial value or were included in the API request.</li>
|
||||
<li>In the OnValidate trigger of a field it&rsquo;s not possible to verify if the API request is an insert or modify operation. Fields can&rsquo;t be protected to be modified during a specific operation, e.g. do not allow to modify during an insert.</li>
|
||||
<li>When implementing the Delegated API Operation pattern, for example to implement a template with default values, the template values should not overwrite the provided values in the API request while non-specified fields should get a value from the template.</li>
|
||||
</ul>
|
||||
<h2 id="description">Description</h2>
|
||||
<p>To mitigate these problems, we can register the fields during the OnValidate trigger in a temporary table. During the delayed insert or modify operation the code knows which fields were part of the API request.</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">field</span><span style="color:#ce5c00;font-weight:bold">(</span>displayName<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Rec<span style="color:#ce5c00;font-weight:bold">.</span>Description<span style="color:#ce5c00;font-weight:bold">)
|
||||
</span><span style="color:#ce5c00;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">trigger</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OnValidate<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>RegisterFieldSet<span style="color:#ce5c00;font-weight:bold">(</span>Rec<span style="color:#ce5c00;font-weight:bold">.</span>FieldNo<span style="color:#ce5c00;font-weight:bold">(</span>Description<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:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">....
|
||||
</span><span style="color:#ce5c00;font-weight:bold">
|
||||
</span><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><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<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><span style="color:#204a87;font-weight:bold">Field</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">temporary</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">local</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>RegisterFieldSet<span style="color:#ce5c00;font-weight:bold">(</span>FieldNumber<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Integer</span><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">if</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>Get<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Database</span><span style="color:#000;font-weight:bold">::</span>Item<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FieldNumber<span style="color:#ce5c00;font-weight:bold">) </span><span style="color:#204a87;font-weight:bold">then</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:#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>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>Init<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>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>TableNo<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Database</span><span style="color:#000;font-weight:bold">::</span>Item<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>&#34;No.&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FieldNumber<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>Insert<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>Now that we have the list of fields that are part of the request, they can be checked during the insert or modify operation. Or they can be handed over to a delegated operation.</p>
|
||||
<p>Some examples to work with the list of fields:</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">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><span style="color:#204a87;font-weight:bold">if</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>Get<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Database</span><span style="color:#000;font-weight:bold">::</span>Item<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Rec<span style="color:#ce5c00;font-weight:bold">.</span>FieldNo<span style="color:#ce5c00;font-weight:bold">(</span>Inventory<span style="color:#ce5c00;font-weight:bold">)) </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Error<span style="color:#ce5c00;font-weight:bold">(</span>InventoryCannotBeChangedInAPostRequestErr<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:#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:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">)
|
||||
</span><span style="color:#ce5c00;font-weight:bold"> </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:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<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 example code combines this with the Delegated API Operation pattern. The codeunit for the delegated operation can use the fieldset to apply a template while keeping the original values from the request.</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:#000;font-weight:bold">;</span><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>TempFieldSet<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>&#34;Field&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ModifiedDateTime<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DateTime</span><span style="color:#ce5c00;font-weight:bold">)
|
||||
</span><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><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateHeader<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>&#34;Config. Template Header&#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>ConfigTemplateManagement<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;Config. Template Management&#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>RecRef<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">RecordRef</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">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">if</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">not</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FindConfigTemplateHeader<span style="color:#ce5c00;font-weight:bold">(</span>Item<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateHeader<span style="color:#ce5c00;font-weight:bold">) </span><span style="color:#204a87;font-weight:bold">then</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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span>GetTable<span style="color:#ce5c00;font-weight:bold">(</span>Item<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:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">if</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateManagement<span style="color:#ce5c00;font-weight:bold">.</span>ApplyTemplate<span style="color:#ce5c00;font-weight:bold">(</span>RecRef<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecRef<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateHeader<span style="color:#ce5c00;font-weight:bold">) </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span>SetTable<span style="color:#ce5c00;font-weight:bold">(</span>Item<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">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><h2 id="benefits">Benefits</h2>
|
||||
<p>Having a list of fields that are part of the API request provides more information during to the insert or modify operation. This helps to implement specific behavior, based on which fields were specified in the API request.</p></description></item><item><title>Docs: begin as an afterword</title><link>https://alguidelines.dev/docs/bestpractices/begin-as-an-afterword/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/docs/bestpractices/begin-as-an-afterword/</guid><description>
|
||||
<p><em>Created by Microsoft, Described by waldo</em></p>
|
||||
<h2 id="description">Description</h2>
|
||||
<p>When <code>begin</code> follows <code>then</code>, <code>else</code>, <code>do</code>, it should be on the same line, preceded by one space character.</p>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
@ -68,6 +68,25 @@
|
|||
</div>
|
||||
<div>
|
||||
<article class="article-teaser article-type-docs">
|
||||
<h3><a href=/docs/patterns/api-register-fieldset/>API Register Fieldset</a></h3>
|
||||
<p></p>
|
||||
<header class=article-meta>
|
||||
<div class="taxonomy taxonomy-terms-article taxo-tags">
|
||||
<h5 class=taxonomy-title>Tags:</h5>
|
||||
<ul class=taxonomy-terms>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/al/ data-taxonomy-term=al><span class=taxonomy-label>AL</span></a></li>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/api/ data-taxonomy-term=api><span class=taxonomy-label>API</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="taxonomy taxonomy-terms-article taxo-categories">
|
||||
<h5 class=taxonomy-title>Categories:</h5>
|
||||
<ul class=taxonomy-terms>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/categories/pattern/ data-taxonomy-term=pattern><span class=taxonomy-label>Pattern</span></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</header>
|
||||
</article>
|
||||
<article class="article-teaser article-type-docs">
|
||||
<h3><a href=/docs/patterns/api-delegate-operation/>Delegate API Operation</a></h3>
|
||||
<p></p>
|
||||
<header class=article-meta>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,90 @@
|
|||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>alguidelines.dev - Business Central Design Patterns – API</title><link>https://alguidelines.dev/tags/api/</link><description>Recent content in API on alguidelines.dev - Business Central Design Patterns</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><atom:link href="https://alguidelines.dev/tags/api/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>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>alguidelines.dev - Business Central Design Patterns – API</title><link>https://alguidelines.dev/tags/api/</link><description>Recent content in API on alguidelines.dev - Business Central Design Patterns</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><atom:link href="https://alguidelines.dev/tags/api/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs: API Register Fieldset</title><link>https://alguidelines.dev/docs/patterns/api-register-fieldset/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://alguidelines.dev/docs/patterns/api-register-fieldset/</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 register the fields that are part of the request body of an API call.</p>
|
||||
<h2 id="context">Context</h2>
|
||||
<p>A request to an API page to insert or modify a record requires a JSON body with the fields and values. It is not required to specify all fields that are exposed by the API page. Only those fields that are specified in the JSON body will be validated with a value. A call to insert a record (http POST) will leave the unspecified fields at their default value. A call to modify a record (http PATCH) will only update the specified fields and leave the other fields to their current value.</p>
|
||||
<h2 id="problem">Problem</h2>
|
||||
<p>The standard behavior can result in a number of challenges:</p>
|
||||
<ul>
|
||||
<li>It&rsquo;s not possible to implement mandatory fields. Especially for fields with an initial value like integers, decimals and booleans the code doesn&rsquo;t know if they are their initial value or were included in the API request.</li>
|
||||
<li>In the OnValidate trigger of a field it&rsquo;s not possible to verify if the API request is an insert or modify operation. Fields can&rsquo;t be protected to be modified during a specific operation, e.g. do not allow to modify during an insert.</li>
|
||||
<li>When implementing the Delegated API Operation pattern, for example to implement a template with default values, the template values should not overwrite the provided values in the API request while non-specified fields should get a value from the template.</li>
|
||||
</ul>
|
||||
<h2 id="description">Description</h2>
|
||||
<p>To mitigate these problems, we can register the fields during the OnValidate trigger in a temporary table. During the delayed insert or modify operation the code knows which fields were part of the API request.</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">field</span><span style="color:#ce5c00;font-weight:bold">(</span>displayName<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Rec<span style="color:#ce5c00;font-weight:bold">.</span>Description<span style="color:#ce5c00;font-weight:bold">)
|
||||
</span><span style="color:#ce5c00;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">trigger</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OnValidate<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>RegisterFieldSet<span style="color:#ce5c00;font-weight:bold">(</span>Rec<span style="color:#ce5c00;font-weight:bold">.</span>FieldNo<span style="color:#ce5c00;font-weight:bold">(</span>Description<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:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">....
|
||||
</span><span style="color:#ce5c00;font-weight:bold">
|
||||
</span><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><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<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><span style="color:#204a87;font-weight:bold">Field</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">temporary</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">local</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>RegisterFieldSet<span style="color:#ce5c00;font-weight:bold">(</span>FieldNumber<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Integer</span><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">if</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>Get<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Database</span><span style="color:#000;font-weight:bold">::</span>Item<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FieldNumber<span style="color:#ce5c00;font-weight:bold">) </span><span style="color:#204a87;font-weight:bold">then</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:#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>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>Init<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>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>TableNo<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Database</span><span style="color:#000;font-weight:bold">::</span>Item<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>&#34;No.&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FieldNumber<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>Insert<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>Now that we have the list of fields that are part of the request, they can be checked during the insert or modify operation. Or they can be handed over to a delegated operation.</p>
|
||||
<p>Some examples to work with the list of fields:</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">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><span style="color:#204a87;font-weight:bold">if</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">.</span>Get<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Database</span><span style="color:#000;font-weight:bold">::</span>Item<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Rec<span style="color:#ce5c00;font-weight:bold">.</span>FieldNo<span style="color:#ce5c00;font-weight:bold">(</span>Inventory<span style="color:#ce5c00;font-weight:bold">)) </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Error<span style="color:#ce5c00;font-weight:bold">(</span>InventoryCannotBeChangedInAPostRequestErr<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:#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:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#ce5c00;font-weight:bold">)
|
||||
</span><span style="color:#ce5c00;font-weight:bold"> </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:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<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 example code combines this with the Delegated API Operation pattern. The codeunit for the delegated operation can use the fieldset to apply a template while keeping the original values from the request.</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:#000;font-weight:bold">;</span><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>TempFieldSet<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>&#34;Field&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ModifiedDateTime<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DateTime</span><span style="color:#ce5c00;font-weight:bold">)
|
||||
</span><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><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateHeader<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>&#34;Config. Template Header&#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>ConfigTemplateManagement<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;Config. Template Management&#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>RecRef<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">RecordRef</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">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">if</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">not</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FindConfigTemplateHeader<span style="color:#ce5c00;font-weight:bold">(</span>Item<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateHeader<span style="color:#ce5c00;font-weight:bold">) </span><span style="color:#204a87;font-weight:bold">then</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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span>GetTable<span style="color:#ce5c00;font-weight:bold">(</span>Item<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:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">if</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateManagement<span style="color:#ce5c00;font-weight:bold">.</span>ApplyTemplate<span style="color:#ce5c00;font-weight:bold">(</span>RecRef<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempFieldSet<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecRef<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateHeader<span style="color:#ce5c00;font-weight:bold">) </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline">
|
||||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span>SetTable<span style="color:#ce5c00;font-weight:bold">(</span>Item<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">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><h2 id="benefits">Benefits</h2>
|
||||
<p>Having a list of fields that are part of the API request provides more information during to the insert or modify operation. This helps to implement specific behavior, based on which fields were specified in the API request.</p></description></item><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>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
@ -66,8 +66,8 @@
|
|||
<h1>Tags</h1>
|
||||
<div class="taxonomy taxonomy-terms-cloud taxo-tags">
|
||||
<ul class=taxonomy-terms>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/al/ data-taxonomy-term=al><span class=taxonomy-label>AL</span><span class=taxonomy-count>27</span></a></li>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/api/ data-taxonomy-term=api><span class=taxonomy-label>API</span><span class=taxonomy-count>1</span></a></li>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/al/ data-taxonomy-term=al><span class=taxonomy-label>AL</span><span class=taxonomy-count>28</span></a></li>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/api/ data-taxonomy-term=api><span class=taxonomy-label>API</span><span class=taxonomy-count>2</span></a></li>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/c/al/ data-taxonomy-term=c/al><span class=taxonomy-label>C/AL</span><span class=taxonomy-count>136</span></a></li>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/decoupling/ data-taxonomy-term=decoupling><span class=taxonomy-label>Decoupling</span><span class=taxonomy-count>2</span></a></li>
|
||||
<li><a class=taxonomy-term href=https://alguidelines.dev/tags/extendability/ data-taxonomy-term=extendability><span class=taxonomy-label>Extendability</span><span class=taxonomy-count>3</span></a></li>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.91817421cb7cbb02b04e622e670b0428.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
<div class="navbar-nav d-none d-lg-block"><input type=search class="form-control td-search-input" placeholder=" Search this site…" aria-label="Search this site…" autocomplete=off data-offline-search-index-json-src=/offline-search-index.15d6fe3997de27ba07da8d70abc12638.json data-offline-search-base-href=/ data-offline-search-max-results=10>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue