alguidelines.dev - Business Central Design Patterns – AL Guidelineshttps://alguidelines.dev/docs/Recent content in AL Guidelines on alguidelines.dev - Business Central Design PatternsHugo -- gohugo.ioen-usDocs: Formatting tipshttps://alguidelines.dev/docs/contributing/formattingtips/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/contributing/formattingtips/ <h1 id="tips-and-tricks-in-terms-of-working-with-markdown-and-hugo">Tips and tricks in terms of working with MarkDown and Hugo</h1> <h2 id="markdown-cheat-sheet">Markdown Cheat Sheet</h2> <p>Here you can find a rather interesting Cheat Sheet regarding markdown: <a href="https://www.markdownguide.org/cheat-sheet">https://www.markdownguide.org/cheat-sheet</a></p> <h2 id="code-fences--syntax-highlighting">Code Fences / Syntax highlighting</h2> <p>The syntax to use codefences is with backticks. If you provide the language after the first block of backticks, github will automatically put that in decent syntax highlighting. So, A simple code fence with AL code, can simply be done by:</p> <pre tabindex="0"><code>```AL procedure ALGuidelinesRock() var Customer: Record Customer; begin Customer.Get(&#39;10000&#39;); Customer.Name := &#39;waldo&#39;; Customer.Modify(true); end; ``` </code></pre><p>Results in:</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="display:flex;"><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>ALGuidelinesRock<span style="color:#ce5c00;font-weight:bold">() </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Customer<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>Customer<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Customer<span style="color:#ce5c00;font-weight:bold">.</span>Get<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#39;10000&#39;</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Customer<span style="color:#ce5c00;font-weight:bold">.</span>Name<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:#4e9a06">&#39;waldo&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Customer<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">Modify</span><span style="color:#ce5c00;font-weight:bold">(</span>true<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></span><span style="display:flex;"><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></span></code></pre></div><h2 id="diagrams-with-mermaid">Diagrams with Mermaid</h2> <p>When providing a documentation, diagrams come in handy. <a href="https://mermaid-js.github.io/mermaid/#/">Mermaid</a> lets you create diagrams and visualizations using text and code.</p> <p>For example the following markdown section:</p> <pre tabindex="0"><code>```mermaid classDiagram Animal &lt;|-- Duck Animal &lt;|-- Fish Animal &lt;|-- Zebra Animal : +int age Animal : +String gender Animal: +isMammal() Animal: +mate() class Duck{ +String beakColor +swim() +quack() } class Fish{ -int sizeInFeet -canEat() } class Zebra{ +bool is_wild +run() } ``` </code></pre><p>Results in:</p> <pre tabindex="0"><code class="language-mermaid" data-lang="mermaid">classDiagram Animal &lt;|-- Duck Animal &lt;|-- Fish Animal &lt;|-- Zebra Animal : +int age Animal : +String gender Animal: +isMammal() Animal: +mate() class Duck{ +String beakColor +swim() +quack() } class Fish{ -int sizeInFeet -canEat() } class Zebra{ +bool is_wild +run() } </code></pre><p>Can&rsquo;t wait to get started? Use the Mermaid <a href="https://mermaid.live/edit">Live Editor</a>.</p> <h2 id="hugo-shortcodes">Hugo Shortcodes</h2> <p>Since we&rsquo;re using &ldquo;Hugo&rdquo;, we can use it&rsquo;s shortcode. Here is a reference: <a href="https://gohugo.io/content-management/shortcodes/">https://gohugo.io/content-management/shortcodes/</a></p> <p>It basically means we are able to use easy notations to do cool things. Let&rsquo;s point out some useful shortcodes:</p> <h3 id="twitter">Twitter</h3> <pre tabindex="0"><code>{{&lt; tweet user=&#34;waldo1001&#34; id=&#34;1458787011024805892&#34; &gt;}} </code></pre><p>makes: <blockquote class="twitter-tweet"><p lang="en" dir="ltr">&quot;Code is Poetry!&quot;<a href="https://twitter.com/hashtag/msdyn365bc?src=hash&amp;ref_src=twsrc%5Etfw">#msdyn365bc</a></p>&mdash; waldo (@waldo1001) <a href="https://twitter.com/waldo1001/status/1458787011024805892?ref_src=twsrc%5Etfw">November 11, 2021</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> </p> <h3 id="youtube">YouTube</h3> <pre tabindex="0"><code>{{&lt; youtube QVOMCYitLEc &gt;}} </code></pre><p>makes: <div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"> <iframe src="https://www.youtube.com/embed/QVOMCYitLEc" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" allowfullscreen title="YouTube Video"></iframe> </div> </p> <h3 id="figure">Figure</h3> <pre tabindex="0"><code>{{&lt; figure src=&#34;http://www.waldo.be/wp-content/uploads/2021/11/business-central-logo.png&#34; title=&#34;Business Central&#34; &gt;}} </code></pre><p>makes: <figure> <img src="http://www.waldo.be/wp-content/uploads/2021/11/business-central-logo.png"/> <figcaption> <h4>Business Central</h4> </figcaption> </figure> </p>Docs: Guide to Fork & PRhttps://alguidelines.dev/docs/contributing/forkandpr/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/contributing/forkandpr/ <h2 id="abstract">Abstract</h2> <p>AL Guidelines is a community project, and as such YOU are encouraged to submit corrections and new ideas. In order to get your content included, you must submit a pull request to the GitHub Repository (Located here: <a href="https://github.com/microsoft/alguidelines">https://github.com/microsoft/alguidelines</a>). All Pull Requests are subject to approval by a minimum of three admins.</p> <p>If You are toying with an idea, but You aren&rsquo;t ready to create a document just yet, you are encouraged to create a project discussion thread here: <a href="https://github.com/microsoft/alguidelines/discussions">https://github.com/microsoft/alguidelines/discussions</a></p> <div class="alert alert-warning" role="alert"> <h4 class="alert-heading">Warning</h4> <p>This is a warning. If You haven&rsquo;t worked in collaboration with &ldquo;external&rdquo; GitHub repositories before, please familiarize yourself with that process by visiting:</p> <p><a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests">https://docs.github.com/en/pull-requests/collaborating-with-pull-requests</a></p> </div> <h2 id="steps">Steps</h2> <p>Now that You have decided that You are ready to contribute, these are the steps to take. <div class="alert alert-info" role="alert"> <h4 class="alert-heading">Note</h4> <p>You can read more about this process here:</p> <p><a href="https://docs.github.com/en/get-started/quickstart/contributing-to-projects">https://docs.github.com/en/get-started/quickstart/contributing-to-projects</a></p> </div> </p> <h3 id="step-1-fork">Step 1: Fork</h3> <p>In order to work on the repository, You must <a href="https://docs.github.com/en/get-started/quickstart/fork-a-repo">Fork</a> the repository.</p> <p>By forking the repository, You essentially create a copy into Your own account.</p> <p>Start by going to the GitHub Repository (<a href="https://github.com/microsoft/alguidelines">https://github.com/microsoft/alguidelines</a>), and press the Fork <img src="./fork_button.jpg" alt="Fork Button" title="Fork"></p> <p>Once You have successfully forked the repository, go to your own GitHub repository : <img src="./ForkedRepro.png" alt="Forked Repository Representation" title="Forked repository"></p> <p>You are now able to clone your own repository to your local pc and start editing using your favorite editor. <a href="https://code.visualstudio.com/">Visual Studio Code</a> is perfectly fine for this task.</p> <div class="alert alert-info" role="alert"> <h4 class="alert-heading">Note</h4> <p>You can read more about forking here:</p> <p><a href="https://docs.github.com/en/get-started/quickstart/fork-a-repo">https://docs.github.com/en/get-started/quickstart/fork-a-repo</a></p> </div> <h3 id="step-2-branch">Step 2: Branch</h3> <p>While not necessarily a must, it is always good practice to create a branch off of your forked repository. That will allow you to work on multiple contributions at the same time and won&rsquo;t have to wait for pull requests to be approved before you can continue on your next contribution.</p> <div class="alert alert-info" role="alert"> <h4 class="alert-heading">Note</h4> <p>You can read more about Branches here:</p> <p><a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches">https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches</a></p> </div> <h3 id="step-3-pull-request">Step 3: Pull Request</h3> <p>Once you are happy with your contribution, it&rsquo;s time to create a pull request to propose changes into the main project! This is the final step in producing a fork of someone else&rsquo;s project, and arguably the most important. If you&rsquo;ve made a change that you feel would benefit the community as a whole, you should definitely consider contributing back.</p> <p>To do so, head on over to the repository on GitHub where your project lives. For this example, it would be at <code>https://www.github.com/&lt;your_username&gt;/alguidelines</code>. You&rsquo;ll see a banner indicating that your branch is one commit ahead of microsoft:main. Click <strong>Contribute</strong> and then <strong>Open a pull request.</strong></p> <p>GitHub will bring you to a page that shows the differences between your fork and the microsoft/alguidelines repository. Click <strong>Create pull request.</strong></p> <p>GitHub will bring you to a page where you can enter a title and a description of your changes. <em>It&rsquo;s important to provide as much useful information and a rationale for why you&rsquo;re making this pull request in the first place.</em> The project owners needs to be able to determine whether your change is as useful to everyone as you think it is. Finally, click <strong>Create pull request.</strong></p>Docs: Understanding the Approval Processhttps://alguidelines.dev/docs/contributing/theapprovalprocess/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/contributing/theapprovalprocess/ <p>(coming soon)</p>Docs: Sensitive Data Encapsulationhttps://alguidelines.dev/docs/navpatterns/patterns/security/1-sensitive-data-encapsulation/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/security/1-sensitive-data-encapsulation/ <p><em>By Bogdana Botez at Microsoft Development Center Copenhagen</em></p> <p><a href="Logo-_2D00_-Protected-Data-Encapsulation.png"><img src="Logo-_2D00_-Protected-Data-Encapsulation.png" alt=" "></a></p> <p><strong>Aliases:</strong> Encapsulation, Separation of Concerns [1]</p> <p><strong>Context</strong>: You want to store and protect sensitive data which already exists in a system, but it is not clear which data needs protection and how to store it.</p> <p><strong>Problem</strong>: Sensitive data is scattered and mixed with other data in various parts of the system (passwords residing in the same table with non-sensitive data, part of the private information might be stored in files, hardcoded text constants, hardcoded info as part of the code etc.).</p> <p><strong>Forces:</strong></p> <ul> <li><strong>Obscurity:</strong> sensitive data mixed with other data and code makes it hard to have an overview of what needs to be protected.</li> <li><strong>Effort:</strong> the protection mechanisms needs to be applied multiple times, once for each location of the sensitive data.</li> <li><strong>Diversity:</strong> different data storage mediums can require different protection solutions.</li> <li><strong>Cohesiveness:</strong> code, low importance data, highly sensitive data are all monolithically mixed which might make it hard to select and protect only what is important.</li> <li><strong>Low</strong> <strong>Performance</strong>: protecting all data can slow down the system.</li> </ul> <p><strong>Solution:</strong> Extract and separate sensitive data into a single known repository.</p> <p>To apply this pattern in Dynamics NAV, a table structure similar to Table 1261 Service Password can be used. The Service Password table also contains additional functionality which will help to further apply related patterns like <a href="https://alguidelines.dev/navpatterns/1-patterns/security/3-single-point-of-access/"><strong>Access Control</strong></a> and <a href="https://alguidelines.dev/navpatterns/1-patterns/security/2-data-encryption/"><strong>Encryption</strong></a>.</p> <p>Figure 1 describes the definition of a table which is already available in Dynamics NAV. This table can be used for storing sensitive data. As a minimum, the table only needs two fields:</p> <ol> <li>The key is of type GUID (Globally Unique Identifier), which is a 128-bit value consisting of multiple groups of hexadecimal digits [2]. Each key needs to be unique and will be used for storing and retrieving the protected information.</li> <li>The value (the actual data to be encapsulated) is of type BLOB (Binary Large OBject) [3], which contains the encrypted or un-encrypted data (for encryption, see the related <a href="https://alguidelines.dev/navpatterns/1-patterns/security/2-data-encryption/"><strong>Encryption</strong></a> pattern).</li> </ol> <p><a href="Data-Encapsulation-_2D00_-figure-1.png"><img src="Data-Encapsulation-_2D00_-figure-1.png" alt="Figure 1- Example definition, table used for Data Encapsulation"></a></p> <p><em>Figure 1- Example definition, table used for <strong>Sensitive</strong> <strong>Data</strong> <strong>Encapsulation</strong></em></p> <p>Let&rsquo;s use a software system (which can be a Dynamics NAV extension or customization). Chances are that the system will look similar to the one described in part 1 of Figure 2: there is data handled in various places of the system, on various storage solutions. Intertwined with normal data, there is sensitive data. For example: Dynamics CRM (Customer Relationship Management) connection information could be all stored in one table, and consists of the connection URI (normal data), enabled/disabled status (normal data), and connection password (sensitive data).</p> <p>Figure 2 illustrates the system before and after applying the <strong>Sensitive Data Encapsulation</strong> pattern.</p> <ul> <li>Before: picture part 1 shows the initial system, where most likely the data is scattered across the system. Furthermore, it is stored in different mediums, like <ul> <li>In a table (possible together with low-importance data)</li> <li>Hardcoded (in Dynamics NAV, it can be a text constant, or just plainly typed in the code)</li> <li>In files</li> </ul> </li> </ul> <p>Furthermore, actors which have to interact with the data, need to remember where to find each piece of information and how to retrieve it.</p> <ul> <li>After: the part 2 of Figure 2 shows the same system after application of <strong>Sensitive Data Encapsulation</strong>. Now, all data is stored in one place, and all actors which interact with it can read it from the unique location.</li> </ul> <p><a href="Multi-_2D00_-1-2.JPG"><img src="Multi-_2D00_-1-2.JPG" alt=" "></a></p> <p><em>Figure 2 - Data access before and after <strong>Sensitive</strong> <strong>Data</strong> <strong>Encapsulation.</strong></em></p> <p><strong>Benefits:</strong></p> <ul> <li><strong>Clarity:</strong> when all sensitive data is encapsulated in one place, it is clear which is the information that needs to be protected.</li> <li><strong>Simplicity:</strong> easier to protect just a limited number of known resources when they are grouped.</li> <li><strong>Homogeneity:</strong> the same protection can be applied to all data, since it is stored in the same place.</li> <li><strong>Separation of concerns:</strong> treat each section of the computer program differently, by separating it and clearly addressing its own requirements and limitations. [1]</li> <li><strong>Performance</strong>: data protection techniques like <strong>Access Control</strong> and <strong>Encryption</strong> can now be applied only to the sensitive data (not to everything), which improves the performance of the system.</li> </ul> <p><strong>Drawbacks:</strong></p> <ul> <li><strong>Single point of failure:</strong> a maliciously intended actor has no longer a need to reverse engineer the places where important data is stored. In the unwanted situation when this actor would have already obtained access to the system, they can more easily locate the sensitive information. This is a step towards information disclosure, but mechanisms like <a href="https://alguidelines.dev/navpatterns/1-patterns/security/2-data-encryption/"><strong>Encryption</strong></a> and logging can provide further protection.</li> <li><strong>Limited Text Length</strong>: there is a limit on how long the encrypted text can be. This limit is imposed by the OS encryption service and it depends on the composition of the text as well as on the system specifics. In NAV, we had implemented the Encrypted Text for text values of max 250 chars, which is enough to cover passwords, person ID numbers, credit card info, but it might turn insufficient in other future scenarios.</li> <li><strong>Nomenclature</strong>: the name of the table <strong>Service Password</strong> is too specific, since it started by being used for passwords, but it has the capability and it now contains other sensitive data like API Keys, credit card numbers etc.</li> </ul> <p><strong>References</strong></p> <p>[1] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">https://en.wikipedia.org/wiki/Separation_of_concerns</a>.</p> <p>[2] &ldquo;GUID Structure,&rdquo; [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx">https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx</a>.</p> <p>[3] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Binary_large_object">https://en.wikipedia.org/wiki/Binary_large_object</a>.</p> <p>[4] waldo, &ldquo;How Do I: Manage Companies in Microsoft Dynamics NAV 2013 R2&rdquo;.</p> <p>[5] Microsoft, &ldquo;Multitenant Deployment Architecture,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx</a>.</p> <p>[6] B. Botez, &ldquo;Setup Table design pattern,&rdquo; Microsoft, 2013. [Online]. Available: <a href="https://community.dynamics.com/nav/w/designpatterns/76.setup-table">https://community.dynamics.com/nav/w/designpatterns/76.setup-table</a>. [Accessed 31 07 2016].</p> <p>[7] &ldquo;Shotgun Surgery,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Shotgun_surgery">https://en.wikipedia.org/wiki/Shotgun_surgery</a>. [Accessed 31 07 2016].</p> <p>[8] M. Fowler, Refactoring: Improving the design of existing code, Addison Wesley, 1999.</p> <p>[9] &ldquo;Masking out,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Data_masking#Masking_out">https://en.wikipedia.org/wiki/Data_masking#Masking_out</a>. [Accessed 29 7 2016].</p> <p>[10] &ldquo;Key Vault,&rdquo; Microsoft, [Online]. Available: <a href="https://azure.microsoft.com/en-us/services/key-vault/">https://azure.microsoft.com/en-us/services/key-vault/</a>.</p> <p>[11] &ldquo;How to: Configure SSL to Secure the Connection to Microsoft Dynamics NAV Web Client,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx</a>. [Accessed 2 8 2016].</p> <p>[12] &ldquo;sniffer,&rdquo; [Online]. Available: <a href="http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm">http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm</a>. [Accessed 02 08 2016].</p>Docs: Data Encryptionhttps://alguidelines.dev/docs/navpatterns/patterns/security/2-data-encryption/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/security/2-data-encryption/ <p><em>By Bogdana Botez at Microsoft Development Center Copenhagen</em></p> <p><a href="Logo-_2D00_-Encryption.png"><img src="Logo-_2D00_-Encryption.png" alt=" "></a></p> <p><strong>Context</strong>: After applying <a href="https://alguidelines.dev/navpatterns/1-patterns/security/1-sensitive-data-encapsulation/"><strong>Sensitive Data Encapsulation</strong></a>, all sensitive data is gathered in a known place in the database. This makes it possible to apply further protection best practices.</p> <p><strong>Problem</strong>: If any non-authorized actor manages to get access to a copy of the database, the sensitive data is immediately available in clear-text.</p> <p><strong>Forces:</strong></p> <ul> <li><strong>Accessibility:</strong> anyone who managed to steal a copy of the database can at once read the sensitive information.</li> </ul> <p><strong>Solution:</strong> Encrypt sensitive data. Dynamics NAV offers a simple mechanism for data encryption, to be used by NAV developers.</p> <p>Figure 1 adds one more step (in continuation of the figure in pattern <strong><a href="https://alguidelines.dev/navpatterns/1-patterns/security/1-sensitive-data-encapsulation/">Sensitive Data Encapsulation</a></strong>), in which the first two panels describe how sensitive data has all been gathered in one known place. This makes the current pattern, <strong>Encryption</strong>, much easier &ndash; since now data needs to be encrypted in only one place. The last panel of Figure 1 shows the system after the next step, <strong>Encryption</strong>, has been implemented. This shows the iterative process of applying patterns and making the code better step by step.</p> <p><a href="Multi-_2D00_-1-2-3.JPG"><img src="Multi-_2D00_-1-2-3.JPG" alt=" "></a></p> <p><em>Figure 1- <strong>Encryption</strong> becomes easier after first applying <a href="https://alguidelines.dev/navpatterns/1-patterns/security/1-sensitive-data-encapsulation/"><strong>Sensitive Data Encapsulation</strong></a>.</em></p> <p><strong>Usage</strong>: in Dynamics NAV, codeunit 1266 Encryption Management offers an API for encryption of data. The available functionality is described in Table 1.</p> <p>Table 1- Encryption functionality in Dynamics NAV (found in codeunit 1266 Encryption Management)</p> <table> <thead> <tr> <th>Procedure</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>EnableEncryption</td> <td>Confirms with the user before enabling encryption in all companies of the current database.</td> </tr> <tr> <td>EnableEncryptionSilently</td> <td>Enables encryption without UI interaction (to be used for web services).</td> </tr> <tr> <td>DisableEncryption</td> <td>Disables encryption. Has a boolean &ldquo;Silent&rdquo; parameter which enables/disables UI interaction.</td> </tr> <tr> <td>Encrypt</td> <td>Checks that encryption is possible before encrypting the given text.</td> </tr> <tr> <td>Decrypt</td> <td>Checks that encryption is possible before decrypting the given text.</td> </tr> <tr> <td>ExportKey</td> <td>If encryption is possible, it shows a confirmation dialog to confirm the export of the encryption key, and proceeds to saving it to a location chosen by the user.</td> </tr> <tr> <td>ImportKey</td> <td>Imports the encryption key from a user chosen location.</td> </tr> <tr> <td>ChangeKey</td> <td>Changes the encryption key.</td> </tr> <tr> <td>IsEncryptionEnabled</td> <td>Returns TRUE is encryption is enabled.</td> </tr> <tr> <td>IsEncryptionPossible</td> <td>Check is the correct key is present, which only works if encryption is enabled.</td> </tr> <tr> <td>DeleteEncryptedDataInAllCompanies</td> <td>Confirms through UI and if the user agrees, deletes all data stored in the Service Password table for all companies in the current database. At the end, it deletes the encryption key.</td> </tr> </tbody> </table> <p><strong>User confirmation of encryption</strong></p> <p>Ideally, encryption should be enabled by default.</p> <p>However, in some versions of Dynamics NAV, there are places where any user who happens to hit a sensitive field (like a password) is asked if they want to encrypt or not. If user confirmation is needed, then let only the security administrators decide (not any random user).</p> <p>To ask the security administrator if they want to enable encryption, plug the code below into the OnValidate trigger of the data field which is to be encrypted. This trigger will then get executed each time there&rsquo;s a change on the password field. For example, if the user is entering a password, then add a call to this procedure to Password &ndash; OnValidate() trigger:</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="display:flex;"><span>EncryptionIsNotActivatedQst@<span style="color:#0000cf;font-weight:bold">1001</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TextConst</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;ENU=Data encryption is not activated. It is recommended that you encrypt data. \\Do you want to open the Data Encryption Management window?&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>CheckEncryption@<span style="color:#0000cf;font-weight:bold">6</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></span><span style="display:flex;"><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></span><span style="display:flex;"><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>ENCRYPTIONENABLED<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>CONFIRM<span style="color:#ce5c00;font-weight:bold">(</span>EncryptionIsNotActivatedQst<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">PAGE</span><span style="color:#ce5c00;font-weight:bold">.</span>RUN<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">PAGE</span><span style="color:#000;font-weight:bold">::</span>&#34;Data Encryption Management&#34;<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></span><span style="display:flex;"><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></span></code></pre></div><p>The code above will guide the user on encrypting, storing the encryption key and choosing a safe password, as follows. Consider for example that NAV is used by a small business, where Stan is the business owner. Hence, Stan has access to all NAV setup and security decisions. Stan wants to enable a connection between NAV and CRM. In NAV, he opens page CRM Connection Setup and enters the URL, user name and password for CRM (Figure 10). When Stan leaves the password field, if data encryption is not enabled, then he sees the confirmation message in Figure 2.</p> <p><a href="Encryption-_2D00_-1.JPG"><img src="Encryption-_2D00_-1.JPG" alt=" "></a></p> <p><em>Figure 2- The administrator is advised to enable encryption.</em></p> <p>Now Stan becomes aware that there is no encryption and has the opportunity to enable it. If he clicks on &ldquo;Yes&rdquo;, Stan will be taken to the Data Encryption Management page (Figure 3).</p> <p><a href="Encryption-_2D00_-2.png"><img src="Encryption-_2D00_-2.png" alt=" "></a></p> <p><em>Figure 3- Data Encryption Management page</em></p> <p>Stan can now choose &ldquo;Enable Encryption&rdquo; from the ribbon which informs him that an encryption key will be created (Figure 4).</p> <p><a href="Encryption-_2D00_-3.png"><img src="Encryption-_2D00_-3.png" alt=" "></a></p> <p><em>Figure 4- The administrator is encouraged to save a copy of the encryption key.</em></p> <p>Stan has the option to save the encryption key in a safe location. He invokes the action Enable Encryption and is guided forward (Figure 5).</p> <p><a href="Encryption-_2D00_-4.png"><img src="Encryption-_2D00_-4.png" alt=" "></a></p> <p><em>Figure 5- The encryption key needs to be protected by a password.</em></p> <p>Stan chooses a password, which in this implementation requires minimum 8 characters with at least one uppercase character, one lowercase character and one digit. If the chosen password is too weak, Stan is given information on the expected complexity (Figure 6).</p> <p><a href="Encryption-_2D00_-5.png"><img src="Encryption-_2D00_-5.png" alt=" "></a></p> <p><em>Figure 6- The administrator chooses a strong password.</em></p> <p>In the end, Stan chooses a location for the encryption key on disk, in a standard file save dialog. The layout of the file save dialog depends on the display target used (web browser, rich client etc.).</p> <p><strong>NAV Usages.</strong> Encryption examples can be found in NAV in the following places:</p> <ul> <li>Page 1260 Bank Data Conv. Service Setup</li> <li>Page 1270 OCR Service Setup</li> <li>Page 5330 CRM Connection Setup</li> <li>Table 1275 Doc. Exch. Service Setup</li> </ul> <p><strong>Benefits:</strong></p> <ul> <li><strong>Protection</strong>: even if the database has been compromised, the sensitive data is encrypted hence not immediately accessible. Combined with best user practices like setting strong passwords, encryption can prove to be a very strong protection mechanism.</li> </ul> <p><strong>Anti-patterns:</strong></p> <ul> <li><strong>Performance:</strong> Do not encrypt everything, because it will have a performance impact on the system. Only important information should be encrypted.</li> <li><strong>System calls and &ldquo;Do It Yourself&rdquo; solutions</strong>: Although system calls for encryptions are available in NAV (ENCRYPT, DECRYPT and &lt;action&gt;ENCRYPTIONKEY), unless there is no other way, refrain from using them directly. Use instead he API in codeunit 1266 Encryption Management, which is safer to use, because it protects against common mistakes (like attempting to encrypt an already encrypted string, enabling encryption in only one company which makes data not usable in another on the same tenant etc.). Use the <a href="https://alguidelines.dev/navpatterns/1-patterns/security/3-single-point-of-access/"><strong>Single Point of Access</strong></a> pattern to handle sensitive data which needs to be encrypted.</li> <li><strong>System-level encryption.</strong> The similar codeunit API 1803 Encrypted Key/Value Management is not intended to be reused by partner NAV developers. Normal NAV users do not have permission to access this resource. This stores sensitive data to be accessed by system NAV functionality.</li> </ul> <p><strong>References</strong></p> <p>[1] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">https://en.wikipedia.org/wiki/Separation_of_concerns</a>.</p> <p>[2] &ldquo;GUID Structure,&rdquo; [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx">https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx</a>.</p> <p>[3] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Binary_large_object">https://en.wikipedia.org/wiki/Binary_large_object</a>.</p> <p>[4] waldo, &ldquo;How Do I: Manage Companies in Microsoft Dynamics NAV 2013 R2&rdquo;.</p> <p>[5] Microsoft, &ldquo;Multitenant Deployment Architecture,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx</a>.</p> <p>[6] B. Botez, &ldquo;Setup Table design pattern,&rdquo; Microsoft, 2013. [Online]. Available: <a href="https://community.dynamics.com/nav/w/designpatterns/76.setup-table">https://community.dynamics.com/nav/w/designpatterns/76.setup-table</a>. [Accessed 31 07 2016].</p> <p>[7] &ldquo;Shotgun Surgery,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Shotgun_surgery">https://en.wikipedia.org/wiki/Shotgun_surgery</a>. [Accessed 31 07 2016].</p> <p>[8] M. Fowler, Refactoring: Improving the design of existing code, Addison Wesley, 1999.</p> <p>[9] &ldquo;Masking out,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Data_masking#Masking_out">https://en.wikipedia.org/wiki/Data_masking#Masking_out</a>. [Accessed 29 7 2016].</p> <p>[10] &ldquo;Key Vault,&rdquo; Microsoft, [Online]. Available: <a href="https://azure.microsoft.com/en-us/services/key-vault/">https://azure.microsoft.com/en-us/services/key-vault/</a>.</p> <p>[11] &ldquo;How to: Configure SSL to Secure the Connection to Microsoft Dynamics NAV Web Client,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx</a>. [Accessed 2 8 2016].</p> <p>[12] &ldquo;sniffer,&rdquo; [Online]. Available: <a href="http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm">http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm</a>. [Accessed 02 08 2016].</p>Docs: Single Point of Accesshttps://alguidelines.dev/docs/navpatterns/patterns/security/3-single-point-of-access/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/security/3-single-point-of-access/ <p><em>By Bogdana Botez at Microsoft Development Center Copenhagen</em></p> <p><a href="Logo-_2D00_-Single-Point-of-Access.png"><img src="Logo-_2D00_-Single-Point-of-Access.png" alt=" "></a></p> <p><strong>Context</strong>: Protected data needs to be used. There are many types of entities which might attempt to use the data.</p> <p><strong>Problem</strong>: If no standard way of accessing data exists, then each entity might attempt to build its own system for handing the sensitive data. The data access layer might be implemented over and over again by each entity, without reuse of known best practices and with a lot of code duplication.</p> <p><strong>Forces:</strong></p> <ul> <li><strong>Code duplication:</strong> if each entity attempts to write its own routines for data access, invariably this will bring duplication.</li> <li><strong>No knowledge reuse:</strong> if a bug is found and fixed in one of the implementations, there is no guarantee that all the other implementations will be updated. For example <ul> <li><strong>Double-Encryption</strong>: lack of care or knowledge could lead a NAV developer to attempt to double-encrypt strings, which would render them unusable.</li> <li><strong>Multi-company configuration [4]</strong>: in NAV, it is possible to store multiple companies on the same tenant [5] database. A developer who has not investigated such a configuration and its consequences on encryption, can attempt to encrypt data in (for example) a Setup Table [6] of only one company, which would make this table unusable from any unencrypted company (since the server will observe that encryption is enabled, and try to retrieve it as it were enabled for all companies and fails).</li> <li><strong>&ldquo;Shotgun surgery&rdquo; [7]:</strong> one change in the data access technique (like a new requirement to validate the user&rsquo;s identity before viewing any protected data), calls for updates in every single implementation of data access, if multiple implementations exist. Hence, one change of requirement triggers multiple efforts to update the product.</li> </ul> </li> </ul> <p><strong>Solution:</strong> In Dynamics NAV the same library which offers <a href="https://alguidelines.dev/navpatterns/1-patterns/security/2-data-encryption/"><strong>Encryption</strong></a>, is also intended to be used as a <strong>Single Point of Access</strong>. Write code to create, read and remove sensitive data only through codeunit 1266 Encryption Management, and never directly.</p> <p>In Figure 9 (figure numbering is continued from pattern <strong><a href="https://alguidelines.dev/navpatterns/1-patterns/security/2-data-encryption/">Encryption</a></strong>), the panels 1, 2 and 3 have applied the <a href="https://alguidelines.dev/navpatterns/1-patterns/security/1-sensitive-data-encapsulation/"><strong>Sensitive Data Encapsulation</strong></a> and <a href="https://alguidelines.dev/navpatterns/1-patterns/security/2-data-encryption/"><strong>Encryption</strong></a> patterns. Once data is encapsulated, no matter if it has been encrypted or not, the next pattern, <strong>Single Point of Access</strong>, becomes available as seen in the panels 2 and 3 of Figure 1.</p> <p>You can observe that, in panel 3, each usage needs to access separately the encrypted data. This means that each usage needs to implement again the encryption capabilities. This is resolved in panel 4, where all users access one common API which encrypts, hence the workload of encryption is moved from the usages, to the API, and needs to be implemented only once.</p> <p><a href="Multi-_2D00_-1-2-3-4.JPG"><img src="Multi-_2D00_-1-2-3-4.JPG" alt=" "></a></p> <p><em>Figure 1- <strong>Single Point of Access</strong> pattern applied.</em></p> <p>This shows how pattern application is an iterative process, where one step follows another. Refactoring [8] the code to apply one pattern, cleans and clarifies the code and in some cases, makes clear the possibility of further refactoring.</p> <p><strong>Usage</strong>: call the procedures available in codeunit 1266 Encryption Management to store and access sensitive data.</p> <p><strong>Benefits:</strong></p> <ul> <li><strong>Simplicity</strong>: only one implementation exists.</li> <li><strong>Knowledge reuse</strong>: if a bug is found and fixed, there is just one place which needs to be repaired. Therefore, there is no risk that some of the usages would still be flawed by the same bug. For example: <ul> <li><strong>Double encryption</strong>: The <strong>Single Point of Access</strong> API already implements knowledge to avoid encryption of already encrypted strings.</li> <li><strong>Multi-company</strong>: The <strong>Single Point of Access</strong> API already implements knowledge for handling encryption in a multi-company setup.</li> <li><strong>Easy maintenance</strong>: a change in specification needs only one code update.</li> </ul> </li> </ul> <p><strong>Consequences:</strong></p> <ul> <li><strong>Single point of failure:</strong> A defect in the access library will affect all usages until it is found and fixed.</li> </ul> <p><strong>References</strong></p> <p>[1] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">https://en.wikipedia.org/wiki/Separation_of_concerns</a>.</p> <p>[2] &ldquo;GUID Structure,&rdquo; [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx">https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx</a>.</p> <p>[3] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Binary_large_object">https://en.wikipedia.org/wiki/Binary_large_object</a>.</p> <p>[4] waldo, &ldquo;How Do I: Manage Companies in Microsoft Dynamics NAV 2013 R2&rdquo;.</p> <p>[5] Microsoft, &ldquo;Multitenant Deployment Architecture,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx</a>.</p> <p>[6] B. Botez, &ldquo;Setup Table design pattern,&rdquo; Microsoft, 2013. [Online]. Available: <a href="https://community.dynamics.com/nav/w/designpatterns/76.setup-table">https://community.dynamics.com/nav/w/designpatterns/76.setup-table</a>. [Accessed 31 07 2016].</p> <p>[7] &ldquo;Shotgun Surgery,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Shotgun_surgery">https://en.wikipedia.org/wiki/Shotgun_surgery</a>. [Accessed 31 07 2016].</p> <p>[8] M. Fowler, Refactoring: Improving the design of existing code, Addison Wesley, 1999.</p> <p>[9] &ldquo;Masking out,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Data_masking#Masking_out">https://en.wikipedia.org/wiki/Data_masking#Masking_out</a>. [Accessed 29 7 2016].</p> <p>[10] &ldquo;Key Vault,&rdquo; Microsoft, [Online]. Available: <a href="https://azure.microsoft.com/en-us/services/key-vault/">https://azure.microsoft.com/en-us/services/key-vault/</a>.</p> <p>[11] &ldquo;How to: Configure SSL to Secure the Connection to Microsoft Dynamics NAV Web Client,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx</a>. [Accessed 2 8 2016].</p> <p>[12] &ldquo;sniffer,&rdquo; [Online]. Available: <a href="http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm">http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm</a>. [Accessed 02 08 2016].</p>Docs: Masked Texthttps://alguidelines.dev/docs/navpatterns/patterns/security/4-masked-text/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/security/4-masked-text/ <p><em>By Bogdana Botez at Microsoft Development Center Copenhagen</em></p> <p><a href="Logo-_2D00_-Masked-Text.png"><img src="Logo-_2D00_-Masked-Text.png" alt=" "></a></p> <p><strong>Aliases:</strong> Masking out</p> <p><strong>Context</strong>: In the user interface (UI) of a software system, the user enters protected information such as a password, an access key, a credit card number etc.</p> <p><strong>Problem</strong>: The entered information is visible during data entry and whenever any user (the one who entered the data, or a foreign user) opens the UI.</p> <p><strong>Forces:</strong></p> <ul> <li><strong>Information disclosure:</strong> sensitive data is visible in the UI.</li> </ul> <p><strong>Solution:</strong> Use the &ldquo;Masked&rdquo; field property to display dots instead of characters on the sensitive text field in the UI.</p> <p><strong>Usage:</strong> Figure 1 shows how an unmasked and a masked field look in Dynamics NAV. On page Microsoft Dynamics CRM Connection Setup, the first two fields (Dynamics CRM URL and User Name) are not masked. The next field (Password) is masked. As the user types text into the Password field, the characters are one by one replaced with dots. When the user had finished typing and had left the Password field (moved focus to another page element), then a pre-defined number of dots is showed in the field, no matter what the real length of the password is. This is done so that the length of the text is not disclosed. Hence, no matter if the text had 5, 10 or 20 characters, as soon as the user leaves the masked field, 10 dots will be visible.</p> <p><a href="Masking-_2D00_-CRM-Connection-Setup-page.PNG"><img src="Masking-_2D00_-CRM-Connection-Setup-page.PNG" alt=" "></a></p> <p><em>Figure 1 - The field &ldquo;Password&rdquo; is masked.</em></p> <p>To apply this pattern in Dynamics NAV, the developer has two choices:</p> <ol> <li><strong>Mask everywhere</strong></li> </ol> <p>Mask the field in all pages which expose it or will expose it in the future. In this case, masking needs to be set at the table level, by opening the table in design mode and setting the field&rsquo;s property ExtendedDatatype=Masked.</p> <ol start="2"> <li><strong>Mask only in selected pages</strong></li> </ol> <p>Mask the field in only a subset of pages. Open the pages where the field should be masked in design mode, open the property page for the field in question, and set ExtendedDatatype=Masked. This option can be used for example when a field should be hidden from most users (in most usual pages), but still visible to administrators in specific pages.</p> <p><strong>Benefits:</strong></p> <ul> <li><strong>Information protection</strong>: sensitive data is stored and can be used by the system, but once entered it is not visible in the UI anymore.</li> </ul> <p><strong>Drawbacks:</strong></p> <ul> <li><strong>&ldquo;Forgotten password&rdquo;:</strong> the text in a masked field is hidden from all users, including users who theoretically have the right to see it. In this case, if the developer wishes to disclose the text only to certain users, they have to write extra code (like a lookup trigger) which will verify the user&rsquo;s permissions and if permitted, show or send the clear-text value to the user who requested it.</li> </ul> <p><strong>References</strong></p> <p>[1] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">https://en.wikipedia.org/wiki/Separation_of_concerns</a>.</p> <p>[2] &ldquo;GUID Structure,&rdquo; [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx">https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx</a>.</p> <p>[3] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Binary_large_object">https://en.wikipedia.org/wiki/Binary_large_object</a>.</p> <p>[4] waldo, &ldquo;How Do I: Manage Companies in Microsoft Dynamics NAV 2013 R2&rdquo;.</p> <p>[5] Microsoft, &ldquo;Multitenant Deployment Architecture,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx</a>.</p> <p>[6] B. Botez, &ldquo;Setup Table design pattern,&rdquo; Microsoft, 2013. [Online]. Available: <a href="https://community.dynamics.com/nav/w/designpatterns/76.setup-table">https://community.dynamics.com/nav/w/designpatterns/76.setup-table</a>. [Accessed 31 07 2016].</p> <p>[7] &ldquo;Shotgun Surgery,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Shotgun_surgery">https://en.wikipedia.org/wiki/Shotgun_surgery</a>. [Accessed 31 07 2016].</p> <p>[8] M. Fowler, Refactoring: Improving the design of existing code, Addison Wesley, 1999.</p> <p>[9] &ldquo;Masking out,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Data_masking">https://en.wikipedia.org/wiki/Data_masking</a>#Masking_out. [Accessed 29 7 2016].</p> <p>[10] &ldquo;Key Vault,&rdquo; Microsoft, [Online]. Available: <a href="https://azure.microsoft.com/en-us/services/key-vault/">https://azure.microsoft.com/en-us/services/key-vault/</a>.</p> <p>[11] &ldquo;How to: Configure SSL to Secure the Connection to Microsoft Dynamics NAV Web Client,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx</a>. [Accessed 2 8 2016].</p> <p>[12] &ldquo;sniffer,&rdquo; [Online]. Available: <a href="http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm">http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm</a>. [Accessed 02 08 2016].</p>Docs: SSL in NAVhttps://alguidelines.dev/docs/navpatterns/patterns/security/5-ssl-in-nav/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/security/5-ssl-in-nav/ <p><em>By Bogdana Botez at Microsoft Development Center Copenhagen</em></p> <p><a href="Logo-_2D00_-SSL.JPG"><img src="Logo-_2D00_-SSL.JPG" alt=" "></a></p> <p><strong>Context</strong>: The security of data transmission is just as important as the security of data storage. When data is transmitted over the web, Secure Sockets Layer (SSL) is available to be used with the web client in Dynamics NAV. Microsoft&rsquo;s NAV cloud solution has SSL enabled by default. However, if a partner company chooses to deploy their own NAV, then they need to handle SSL explicitly.</p> <p><strong>Problem</strong>: Although data is stored securely, before it even gets to be stored, it needs to travel the web on a client-server connection, where it is vulnerable.</p> <p><strong>Forces:</strong></p> <ul> <li><strong>Insecure communication:</strong> When the user enters a password, if unprotected, a network sniffer [12] could catch and read it. A sniffer is either a software program or hardware device which examine network traffic. Years ago, sniffers were tools used exclusively by professional network engineers, but nowadays, they are also popular with Internet hackers and people just curious about networking. A public Wi-Fi network could easily be eavesdropped by an unwanted actor.</li> </ul> <p>By using data storage patterns like <strong>Sensitive Data Encapsulation</strong>, <strong>Encryption, Single Point of Access</strong> or <strong>Azure Key Vault</strong>, the sensitive data is preserved securely in the implementation of Dynamics NAV. But before it gets into a secure store, this data needs to be transmitted from the user, through a user interface, on a client-server connection and all the way to the database. Is the data safe while being transmitted?</p> <p><strong>Solution:</strong> To protect the data before it reaches the server, remember to configure SSL (Secure Sockets Layer) in Dynamics NAV.</p> <p><em>SSL</em> is a web protocol that encrypts data that is transmitted over a network to make the data and the network more secure and reliable. A website that is enabled with SSL uses Hypertext Transfer Protocol Secure (HTTPS) instead of Hypertext Transfer Protocol (HTTP) as a communication protocol.</p> <p>Figure 1 shows data communication between the client (where the user enters data) and the server (which connects further to the database). Without encryption (left side), data is available in clear text over the wire. A person equipped with a network sniffer can easily intercept and read it. On the right side of the picture, SSL is used to encrypt the user&rsquo;s data. Sniffing the traffic would capture the encrypted stream, but access to the real content would be impeded by encryption.</p> <p><a href="SSL-_2D00_-before-and-after.PNG"><img src="SSL-_2D00_-before-and-after.PNG" alt=" "></a></p> <p><em>Figure 1 - Data transmission before (http://&hellip;) and after SSL encryption (https://&hellip;).</em></p> <p><strong>Usage</strong>: the latest information about how to configure SSL for the web client in Dynamics NAV is found online at on MSDN at <a href="https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx</a>.</p> <p><strong>Benefits:</strong></p> <ul> <li><strong>Secure communication</strong>: encryption protects the data transmitted over a network, so the data is safe all the way on its journey from the user to the database.</li> </ul> <p><strong>Consequences:</strong></p> <ul> <li><strong>Awareness:</strong> a NAV system administrator might not be aware that they need to enable SSL when using the web client.</li> <li><strong>Extra work:</strong> there is extra effort to enable SSL on a self-administered NAV system. The good news is that Microsoft&rsquo;s cloud NAV solution has SSL by default and no extra work is required from the developer on that aspect.</li> </ul> <p><strong>References</strong></p> <p>[1] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">https://en.wikipedia.org/wiki/Separation_of_concerns</a>.</p> <p>[2] &ldquo;GUID Structure,&rdquo; [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx">https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx</a>.</p> <p>[3] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Binary_large_object">https://en.wikipedia.org/wiki/Binary_large_object</a>.</p> <p>[4] waldo, &ldquo;How Do I: Manage Companies in Microsoft Dynamics NAV 2013 R2&rdquo;.</p> <p>[5] Microsoft, &ldquo;Multitenant Deployment Architecture,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx</a>.</p> <p>[6] B. Botez, &ldquo;Setup Table design pattern,&rdquo; Microsoft, 2013. [Online]. Available: <a href="https://community.dynamics.com/nav/w/designpatterns/76.setup-table">https://community.dynamics.com/nav/w/designpatterns/76.setup-table</a>. [Accessed 31 07 2016].</p> <p>[7] &ldquo;Shotgun Surgery,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Shotgun_surgery">https://en.wikipedia.org/wiki/Shotgun_surgery</a>. [Accessed 31 07 2016].</p> <p>[8] M. Fowler, Refactoring: Improving the design of existing code, Addison Wesley, 1999.</p> <p>[9] &ldquo;Masking out,&rdquo; [Online]. Available: <a href="https://en.wikipedia.org/wiki/Data_masking#Masking_out">https://en.wikipedia.org/wiki/Data_masking#Masking_out</a>. [Accessed 29 7 2016].</p> <p>[10] &ldquo;Key Vault,&rdquo; Microsoft, [Online]. Available: <a href="https://azure.microsoft.com/en-us/services/key-vault/">https://azure.microsoft.com/en-us/services/key-vault/</a>.</p> <p>[11] &ldquo;How to: Configure SSL to Secure the Connection to Microsoft Dynamics NAV Web Client,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx</a>. [Accessed 2 8 2016].</p> <p>[12] &ldquo;sniffer,&rdquo; [Online]. Available: <a href="http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm">http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm</a>. [Accessed 02 08 2016].</p>Docs: Actions - Imageshttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/ux/actions-images/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/ux/actions-images/ <p>All actions must have an image assigned to them.</p> <p>Bad code</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="display:flex;"><span>{<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">7</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">;</span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">Action</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>CaptionML=ENU=Customer<span style="color:#f8f8f8;text-decoration:underline"> </span>-<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">&amp;</span>Balance<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RunObject=<span style="color:#204a87;font-weight:bold">Report</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">121</span><span style="color:#f8f8f8;text-decoration:underline"> </span>}<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>Good code</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="display:flex;"><span>{<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">7</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">;</span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">Action</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>CaptionML=ENU=Customer<span style="color:#f8f8f8;text-decoration:underline"> </span>-<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">&amp;</span>Balance<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RunObject=<span style="color:#204a87;font-weight:bold">Report</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">121</span><span style="color:#f8f8f8;text-decoration:underline"> </span>}<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Image=<span style="color:#204a87;font-weight:bold">Report</span><span style="color:#f8f8f8;text-decoration:underline"> </span>}<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div>Docs: Activity Logshttps://alguidelines.dev/docs/navpatterns/patterns/activity-log/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/activity-log/ <p><em>Originally by Ciprian Iordache at Microsoft Development Center Copenhagen</em></p> <h2 id="activity-log">Activity Log</h2> <p><strong>Abstract</strong></p> <p>The Activity Log pattern tracks execution of activities. This is a Dynamics NAV specific implementation of the <a href="http://martinfowler.com/eaaDev/AuditLog.html">Audit Log</a> pattern.</p> <p><a href="Activity-Log.jpg"><img src="Activity-Log.jpg" alt=" "></a></p> <p><strong>Problem</strong></p> <p>In general, integrating with external systems can be very challenging, due to the complexity of the situation &ndash; connectivity issues, asynchronous operations, user errors, etc. These challenges require sometimes re-trying several times, polling the external system, re-send/re-get data as all these activities can succeed but can very well fail.</p> <p>Similar challenges exist in situations where a lengthy, complex task, composed of different steps is to be executed by various people in various timeframes. In case of errors (but sometimes also in case of success) there will be a need to track these activities to see what happened and the actual person which did a specific step.</p> <p>In all these cases, we need to be able to troubleshoot.</p> <p>A tracking/logging functionality could be implemented for each activity/step separately, but this would lead to code duplication and problems in maintaining the code in future.</p> <p>In NAV there is already the Change Log functionality which can record all the data changes that have been done to specific tables, specific fields. However, this functionality is not available for activities. Also, there are few places where separate logging/tracking implementations were done but the current pattern proposes an unified, central way of data recording and enables the user to track all/most of the activities.</p> <p><strong>Solution</strong></p> <p>The Activity Log pattern tracks specific outcome of the activities, in order to be able to assess what went wrong/fine or who performed a specific activity.</p> <p>Activity Log pattern</p> <ul> <li>records the activity and its outcome (error or success messages)</li> <li>assembles all messages in one central view and presents them to the user filtered for the specific activity and ordered in reverse chronological order.</li> </ul> <p>Figure below illustrates the how the Activity Log manifests in the UI. The figure shows a part of an activity log for a posted document that was sent to the document exchange service and illustrates both successful and failed activities.</p> <p><a href="Activity-Log-NAV.jpg"><img src="Activity-Log-NAV.jpg" alt=" "></a></p> <p>This functionality is implemented in the following way - Activity Log table (TAB710) contains a simple function that allows you to log the result of a task or activity:</p> <p>ActivityLog.LogActivity(ContextRecordID,ActivityLog.Status::Failed,ContextDescription,ActivityDescription,ActivityMessage);</p> <p>Similar to TAB700 for Error Messaging, the Activity Log table contains a RECORDID that is a link to the parent/context entity. That permits the Activity Log to be used in a generic way, for any kind of entities (tables) and it also permits filtering the data to a specific related entity only before being presenting to the user.</p> <p>The following parameters should be provided to the function:</p> <ul> <li>RecordID: The record/context for which the activity is logged</li> <li>Status: The task/activity outcome</li> <li>Descriptions/Messages: fields that will clearly describe the state and outcome of the task</li> </ul> <p>To show the log, add a page action, with the caption including the name &ldquo;&lt;prefix&gt; Log&rdquo; and link it to the image named &ldquo;Log&rdquo;:</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="display:flex;"><span>{<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">;</span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">Action</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Name=ActivityLog<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>CaptionML=ENU=<span style="color:#4e9a06">&#39;Activity Log&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ToolTipML=ENU=<span style="color:#4e9a06">&#39;View the status and any errors if the document was sent as an electronic document or OCR file through the document exchange service.&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ApplicationArea=#Basic<span style="color:#000;font-weight:bold">,</span>#Suite<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Image=Log<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>OnAction=<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ActivityLog@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#0000cf;font-weight:bold">710</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ActivityLog<span style="color:#ce5c00;font-weight:bold">.</span>ShowEntries<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">RECORDID</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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>}<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p><strong>NAV usages</strong></p> <p>In Dynamics NAV 2016, there is a new feature for sending documents in electronic format to a document exchange service. In this case, sending documents requires multiple steps as it is an asynchronous activity and as such, in order to keep track of what&rsquo;s happening and when the Activity Log functionality was used. That offers later the possibility to see who sent and when a document was sent, when it was dispatched, if any dispatch errors and how many tries have been made until the document was finally dispatched or rejected.</p> <p>So as usages in NAV 2016, we have the document exchange and OCR features plus the related posted documents involved in the document exchange feature.</p> <ul> <li>COD1294.TXT</li> <li>COD1410.TXT</li> <li>PAG1270.TXT</li> <li>PAG1275.TXT</li> <li>PAG143.TXT</li> <li>PAG144.TXT</li> <li>PAG189.TXT</li> <li>TAB112.TXT</li> <li>TAB114.TXT</li> <li>TAB130.TXT</li> </ul> <p><strong>Ideas for improvement</strong></p> <p>Replace the scattered similar functionality (as mentioned above, we have several places having close functionality or similar requirements) with this new pattern.</p> <p><strong>Consequences</strong></p> <ul> <li>Use with caution, similar to the Change Log functionality, as if the pattern will be used extensively in all the activities/operations within NAV, the table might become large containing many records and might cause some performance issues when presenting the data to the client (filtering on the specific activity).</li> <li>Do not log private or confidential information (passwords, amounts, salaries, sensitive data), unless you are ok with this data to be showed to all users (even to users which normally would not have access to this data), thus overriding the permission sets.</li> <li>Log only essential information (quality over quantity). Can the logged data be used to analyze the problem, or is it just junk data?</li> </ul> <p><strong>NAV Versions</strong></p> <p>Supported from NAV 2016</p> <p><strong>Related Topics</strong></p> <p>Error Message Processing &ndash; provides a similar view and uses similar concepts: has a generic implementation (uses as link the same RECORDID feature) and uses same filtering functionality when displaying the data to the user.</p> <p>Audit Log &ndash; as mentioned in the beginning, this pattern is a NAV specific implementation of the audit log pattern.</p>Docs: Argument Tablehttps://alguidelines.dev/docs/navpatterns/patterns/argument-table/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/argument-table/ <p><em>Originally By Nikola Kukrika and waldo</em></p> <h3 id="abstract">Abstract</h3> <p>The Argument Table pattern is used to provide an extension point for adding new arguments without changing the signature. By grouping multiple arguments into a table the code becomes more readable (function signature and the usage of the function).</p> <p><a href="0218.Argument-Table-image.png"><img src="0218.Argument-Table-image.png" alt=" "></a></p> <h3 id="problem">Problem</h3> <p>In CAL overloading function signature is not supported. It is also not possible to provide default values for the function arguments.</p> <p>When an argument needs to be added to the function, the existing function needs to be extracted to a new method with an additional argument and the original function will call new method. This will cause an upgrade problem in the future, since the entire body of the method is replaced.</p> <p>Second commonly occurring problem is option duplication. In order to pass options often they are duplicated in the signature.</p> <p>The last problem that can be solved is high number of arguments. Functions with a high number of arguments are hard to understand. Having arguments grouped within the table with a meaningful name will improve readability and make code easier to understanding.</p> <p>Few examples of the bad implementations are as illustrated here:</p> <h4 id="bad-example-1">Bad example 1</h4> <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="display:flex;"><span><span style="color:#204a87;font-weight:bold">PROCEDURE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FillInVATReturnData@<span style="color:#0000cf;font-weight:bold">1200001</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>DeclarationID@<span style="color:#0000cf;font-weight:bold">1200000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Code</span><span style="color:#f8f8f8;text-decoration:underline"> </span>[<span style="color:#0000cf;font-weight:bold">20</span>]<span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span>LineID@<span style="color:#0000cf;font-weight:bold">1200001</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Code</span><span style="color:#f8f8f8;text-decoration:underline"> </span>[<span style="color:#0000cf;font-weight:bold">20</span>]<span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span>PeerID@<span style="color:#0000cf;font-weight:bold">1200002</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Code</span><span style="color:#f8f8f8;text-decoration:underline"> </span>[<span style="color:#0000cf;font-weight:bold">20</span>]<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>DocumentNo@<span style="color:#0000cf;font-weight:bold">1200003</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Code</span>[<span style="color:#0000cf;font-weight:bold">20</span>]<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>NumberOfCopies@<span style="color:#0000cf;font-weight:bold">1200007</span><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:#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>Uploaded@<span style="color:#0000cf;font-weight:bold">1200004</span><span style="color:#f8f8f8;text-decoration:underline"> </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:#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>Correction@<span style="color:#0000cf;font-weight:bold">1200005</span><span style="color:#f8f8f8;text-decoration:underline"> </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:#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>HasValidationErr@<span style="color:#0000cf;font-weight:bold">1200006</span><span style="color:#f8f8f8;text-decoration:underline"> </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:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p><strong>Call</strong></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="display:flex;"><span>FillInVATReturnData<span style="color:#ce5c00;font-weight:bold">(</span>NoSeries<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NextLineID<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>CustomerID<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>DocumentNo<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>SingleCopy<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>???<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>??<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </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:#ce5c00;font-weight:bold">...) </span></span></span></code></pre></div><p>In this example the code is hard to read and understand. Adding an additional argument will require refactoring of the existing function. Each time a new argument is added a new function will be created.</p> <h4 id="bad-example-2">Bad example 2</h4> <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="display:flex;"><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>GetTableSyncSetupW1@<span style="color:#0000cf;font-weight:bold">3</span><span style="color:#ce5c00;font-weight:bold">(</span>OldTableId@<span style="color:#0000cf;font-weight:bold">1002</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#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>UpgradeTableId@<span style="color:#0000cf;font-weight:bold">1001</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#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>TableUpgradeMode@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;Check, Copy, Move, Force&#39;</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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">CASE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OldTableId<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">OF</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>&#34;Sales Header&#34;<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SetTableSyncSetup<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span>TableUpgradeMode<span style="color:#000;font-weight:bold">::</span>Check<span style="color:#000;font-weight:bold">,</span>UpgradeTableId<span style="color:#000;font-weight:bold">,</span>TableUpgradeMode<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></span><span style="display:flex;"><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>&#34;Posting Exch. Column Def&#34;<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SetTableSyncSetup<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">104025</span><span style="color:#000;font-weight:bold">,</span>TableUpgradeMode<span style="color:#000;font-weight:bold">::</span>Copy<span style="color:#000;font-weight:bold">,</span>UpgradeTableId<span style="color:#000;font-weight:bold">,</span>TableUpgradeMode<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></span><span style="display:flex;"><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>&#34;Payment Export Data&#34;<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SetTableSyncSetup<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span>TableUpgradeMode<span style="color:#000;font-weight:bold">::</span>Force<span style="color:#000;font-weight:bold">,</span>UpgradeTableId<span style="color:#000;font-weight:bold">,</span>TableUpgradeMode<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><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></span><span style="display:flex;"><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>TRUE<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></span><span style="display:flex;"><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></span></code></pre></div><p>In this example each time a new argument is added all function calls will have to be updated. Option is duplicated in the signature, which will cause issues if a new option is defined or the existing options are renamed.</p> <h3 id="solution">Solution</h3> <p>By grouping the arguments within the table it is possible to add additional argument and reuse it where it is needed without changing the signature.</p> <p>Multiple parameters are grouped within the single object with a meaningful name so the code becomes more readable.</p> <p>It is possible to assign default values and to have the code validation.</p> <p>Argument table should preferably be a temporary table since the implementation is simpler.</p> <p>The examples of usages addressing problems shown above are:</p> <h4 id="good-example-1">Good example 1</h4> <p>New table</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="display:flex;"><span>TAB<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">50003</span><span style="color:#f8f8f8;text-decoration:underline"> </span>VAT<span style="color:#f8f8f8;text-decoration:underline"> </span>Return<span style="color:#f8f8f8;text-decoration:underline"> </span>Data<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>FillInVATReturnData@<span style="color:#0000cf;font-weight:bold">1200001</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>VATReturnData@<span style="color:#0000cf;font-weight:bold">1200000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#0000cf;font-weight:bold">50003</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VATReturnData<span style="color:#ce5c00;font-weight:bold">.</span>INIT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VATReturnData<span style="color:#ce5c00;font-weight:bold">.</span>NumberOfCopies<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>GetDefaultNumberOfCopies<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VATReturnData<span style="color:#ce5c00;font-weight:bold">.</span>Uploaded<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FALSE<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>FillInVATReturnData<span style="color:#ce5c00;font-weight:bold">(</span>VATReturnData<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></span></code></pre></div><p>By introducing an argument table, code is much more readable since there is a single argument for a function. It is easy to see which arguments are passed in and which are modified in a function.</p> <h4 id="good-example-2">Good example 2</h4> <p>Good example</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">PROCEDURE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>GetTableSyncSetupW1@<span style="color:#0000cf;font-weight:bold">3</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>TableSynchSetup@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#0000cf;font-weight:bold">2000000135</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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SetTableSyncSetup<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>&#34;Sales Header&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span>TableSynchSetup<span style="color:#ce5c00;font-weight:bold">.</span>Mode<span style="color:#000;font-weight:bold">::</span>Check<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SetTableSyncSetup<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>&#34;Posting Exch. Column Def&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#0000cf;font-weight:bold">104025</span><span style="color:#000;font-weight:bold">,</span>TableSynchSetup<span style="color:#ce5c00;font-weight:bold">.</span>Mode<span style="color:#000;font-weight:bold">::</span>Copy<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SetTableSyncSetup<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>&#34;Payment Export Data&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span>TableSynchSetup<span style="color:#ce5c00;font-weight:bold">.</span>Mode<span style="color:#000;font-weight:bold">::</span>Force<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></span><span style="display:flex;"><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></span></code></pre></div><p>Option definition is not encapsulated within the table. Arguments are grouped and we can add additional arguments without the need to change the signature.</p> <h3 id="downsides">Downsides</h3> <p>You need to create one more table</p> <p>Complex types can&rsquo;t be embedded as fields in tables (cannot have a record field type etc).</p> <h3 id="nav-usages">NAV Usages</h3> <p>Upgrade Codeunits</p> <h3 id="related-patterns">Related Patterns</h3> <p>Posting Routine, Select behavior: Setting fields on existing records in order not to change the signatures.</p>Docs: Begin as an 'After Word'https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/begin-as-an-afterword/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/begin-as-an-afterword/ <p>When BEGIN follows THEN, ELSE, DO, it should be on the same line, preceded by one space character.</p> <p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ICPartnerRefType<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span>ICPartnerRefType<span style="color:#000;font-weight:bold">::</span>&#34;Common Item No.&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></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></span></code></pre></div><p>Good code</p> <pre tabindex="0"><code>IF ICPartnerRefType = ICPartnerRefType::&#34;Common Item No.&#34; THEN BEGIN ... END; </code></pre>Docs: Begin-End - Compound Onlyhttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/begin-end/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/begin-end/ <p>Only use BEGIN..END to enclose compound statements.</p> <p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>IsAssemblyOutputLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TESTFIELD</span><span style="color:#ce5c00;font-weight:bold">(</span>&#34;Order Line No.&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#0000cf;font-weight:bold">0</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></span><span style="display:flex;"><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></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>IsAssemblyOutputLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TESTFIELD</span><span style="color:#ce5c00;font-weight:bold">(</span>&#34;Order Line No.&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#0000cf;font-weight:bold">0</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></span></code></pre></div><p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>Exception</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="display:flex;"><span><span style="color:#8f5902;font-style:italic">// Except for this case </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>X<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><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>Y<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DO</span><span style="color:#f8f8f8;text-decoration:underline"> </span>SOMETHING<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">END</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">not</span><span style="color:#f8f8f8;text-decoration:underline"> </span>X<span style="color:#ce5c00;font-weight:bold">) </span></span></span></code></pre></div>Docs: Binary Operator to Start Linehttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/binary-operator-line-start/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/binary-operator-line-start/ <p>Do not start a line with a binary operator.</p> <p>Bad code</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="display:flex;"><span>&#34;Quantity to Ship&#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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Quantity<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>-<span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Quantity Shipped&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>Good code</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="display:flex;"><span>&#34;Quantity to Ship&#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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Quantity<span style="color:#f8f8f8;text-decoration:underline"> </span>-<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Quantity Shipped&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div>Docs: Blank Lineshttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/blank-lines/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/blank-lines/ <p>Do not use blank lines at the beginning or end of any functions, after BEGIN, before END, or inside multiline expressions.</p> <p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">PROCEDURE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MATRIX_OnDrillDown@<span style="color:#0000cf;font-weight:bold">1133</span><span style="color:#ce5c00;font-weight:bold">(</span>MATRIX_ColumnOrdinal<span style="color:#f8f8f8;text-decoration:underline"> </span><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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SetupDrillDownCol<span style="color:#ce5c00;font-weight:bold">(</span>MATRIX_ColumnOrdinal<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DrillDown<span style="color:#ce5c00;font-weight:bold">(</span>FALSE<span style="color:#000;font-weight:bold">,</span>ValueType<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">PROCEDURE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MATRIX_OnDrillDown@<span style="color:#0000cf;font-weight:bold">1133</span><span style="color:#ce5c00;font-weight:bold">(</span>MATRIX_ColumnOrdinal<span style="color:#f8f8f8;text-decoration:underline"> </span><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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SetupDrillDownCol<span style="color:#ce5c00;font-weight:bold">(</span>MATRIX_ColumnOrdinal<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DrillDown<span style="color:#ce5c00;font-weight:bold">(</span>FALSE<span style="color:#000;font-weight:bold">,</span>ValueType<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></span><span style="display:flex;"><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></span></code></pre></div><p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NameIsValid<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">AND</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Name2IsValid<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NameIsValid<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">AND</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Name2IsValid<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div>Docs: By Reference Parametershttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/by-reference-parameters/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/by-reference-parameters/ <p>Do not declare parameters by reference if their values are not intended to be changed.</p> <p>Unintentional value changes might propagate. Also, it might lead people to believe that value changes are intended.</p> <p>Bad code</p> <pre><code>LOCAL PROCEDURE ShowMessage@15(VAR Text@1000 : Text[250]); BEGIN Text := GetMessageText; IF (Text &lt;&gt; '') AND GenJnlLineInserted THEN MESSAGE(Text); END; </code></pre> <p>Good code</p> <pre><code>LOCAL PROCEDURE ShowMessage@15(Text@1000 : Text[250]); BEGIN Text := GetMessageText; IF (Text &lt;&gt; '') AND GenJnlLineInserted THEN MESSAGE(Text); END; </code></pre>Docs: Cached Web Server Callshttps://alguidelines.dev/docs/navpatterns/patterns/cached-web-service-calls/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/cached-web-service-calls/ <p><em>Originally by Mostafa Balat, Microsoft Development Center Copenhagen</em></p> <h2 id="abstract">Abstract</h2> <p>In a service-oriented deployment, web services are used to extend NAV&rsquo;s functionality and reach. Depending on how volatile this data is and the corresponding usage scheme, it is expected to be up-to-date within a pre-defined period of time (e.g. once a day).</p> <h2 id="description">Description</h2> <p>When NAV is integrated with external services, then the user scenarios become dependent on the data and functions offered by such services. Eventually, there are different approaches through which the external data can be retrieved, stored and used.</p> <ul> <li>Dynamic: either exposed by the external service itself or by a separate catalog that NAV can query. <ul> <li>Advantage: data is always up-to-date</li> <li>Disadvantage: it requires constant connection to the data source.</li> </ul> </li> <li>Static: hard-coded in the database for the user to benefit from. <ul> <li>Advantage: data is promptly available when needed.</li> <li>Disadvantage: if data changes at some point, it will require a maintenance effort, which exposes the business process to a risk of failure.</li> </ul> </li> <li>Cached: offered through an external service and gets pulled according to a pre-defined refresh rate or manually. <ul> <li>Advantage: data is &lsquo;up-to-date&rsquo; within the rules acceptable by the business process, without extra load on the network resources or the external service.</li> <li>Disadvantage: if data changes while the auto-refresh did not happen yet, the user may not have access to the latest data; however, the user can manually force a refresh of the data, if asked to do so.</li> </ul> </li> </ul> <h3 id="when-to-use-it">When to Use It</h3> <p>Offer data in lookups that were cached from an external service.</p> <h3 id="diagram">Diagram</h3> <p><a href="Cached_5F00_Web_5F00_Service_5F00_Calls_5F00_Diagram.png"><img src="Cached_5F00_Web_5F00_Service_5F00_Calls_5F00_Diagram.png" alt=" "></a></p> <h2 id="usage">Usage</h2> <p>Set up an NAV feature to consume the data from an external service. Refresh the data on a pre-defined refresh rate (e.g. once a day) or when enforced by a power user or an admin. Cache the data in a table and offer it in lookups, as applicable.</p> <h2 id="nav-specific-example">NAV Specific Example</h2> <h3 id="overview">Overview</h3> <p><strong>PAG1259 Bank Name - Data Conv. List</strong> offers the required functionality to refresh and display the list of bank names needed to specify which file format to convert to. The page can be accessed from <strong>PAG1260 Bank Data Conv. Service Setup</strong> to display all available bank names. It is also used as a lookup on <strong>PAG370 Bank Account Card</strong>, where it offers a filtered view of the cached bank names based on the Country/Region Code field.</p> <p>If <strong>PAG1259 Bank Name - Data Conv. List</strong> is being open and the cached data is &lsquo;old&rsquo;, it refreshes the cache. The cached data is stored in <strong>TAB1259 Bank Data Conv. Bank</strong>. Meanwhile, the user has the chance to refresh the data using</p> <h3 id="code-sample">Code Sample</h3> <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="display:flex;"><span>OnInit=<span style="color:#204a87;font-weight:bold">BEGIN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ShortTimeout<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:#0000cf;font-weight:bold">5000</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>LongTimeout<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:#0000cf;font-weight:bold">30000</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>OnOpenPage=<span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>BankDataConvBank@<span style="color:#0000cf;font-weight:bold">1002</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#0000cf;font-weight:bold">1259</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ImpBankListExtDataHndl@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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><span style="color:#0000cf;font-weight:bold">1289</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>CountryRegionCode@<span style="color:#0000cf;font-weight:bold">1004</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>HideErrors@<span style="color:#0000cf;font-weight:bold">1003</span><span style="color:#f8f8f8;text-decoration:underline"> </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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>CountryRegionCode<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>IdentifyCountryRegionCode<span style="color:#ce5c00;font-weight:bold">(</span>Rec<span style="color:#000;font-weight:bold">,</span>GETFILTER<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Country/Region Code&#34;<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></span><span style="display:flex;"><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>BankDataConvBank<span style="color:#ce5c00;font-weight:bold">.</span>ISEMPTY<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ImpBankListExtDataHndl<span style="color:#ce5c00;font-weight:bold">.</span>GetBankListFromConversionService<span style="color:#ce5c00;font-weight:bold">(</span>HideErrors<span style="color:#000;font-weight:bold">,</span>CountryRegionCode<span style="color:#000;font-weight:bold">,</span>ShortTimeout<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></span><span style="display:flex;"><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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RefreshBankNamesOlderThanToday<span style="color:#ce5c00;font-weight:bold">(</span>CountryRegionCode<span style="color:#000;font-weight:bold">,</span>HideErrors<span style="color:#000;font-weight:bold">,</span>ShortTimeout<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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>OnAction=<span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ImpBankListExtDataHndl@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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><span style="color:#0000cf;font-weight:bold">1289</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>FilterNotUsed@<span style="color:#0000cf;font-weight:bold">1001</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ShowErrors@<span style="color:#0000cf;font-weight:bold">1003</span><span style="color:#f8f8f8;text-decoration:underline"> </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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ShowErrors<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TRUE<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ImpBankListExtDataHndl<span style="color:#ce5c00;font-weight:bold">.</span>GetBankListFromConversionService<span style="color:#ce5c00;font-weight:bold">(</span>ShowErrors<span style="color:#000;font-weight:bold">,</span>FilterNotUsed<span style="color:#000;font-weight:bold">,</span>LongTimeout<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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>IdentifyCountryRegionCode@<span style="color:#0000cf;font-weight:bold">1</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>BankDataConvBank@<span style="color:#0000cf;font-weight:bold">1002</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#0000cf;font-weight:bold">1259</span><span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">Filter</span>@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</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">Text</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>CompanyInformation@<span style="color:#0000cf;font-weight:bold">1001</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#0000cf;font-weight:bold">79</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>BlankFilter@<span style="color:#0000cf;font-weight:bold">1003</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>BlankFilter<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:#4e9a06">&#39;&#39;&#39;&#39;&#39;&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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">Filter</span><span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span>BlankFilter<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>CompanyInformation<span style="color:#ce5c00;font-weight:bold">.</span>GET<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>BankDataConvBank<span style="color:#ce5c00;font-weight:bold">.</span>SETFILTER<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Country/Region Code&#34;<span style="color:#000;font-weight:bold">,</span>CompanyInformation<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Country/Region Code&#34;<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></span><span style="display:flex;"><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>BankDataConvBank<span style="color:#ce5c00;font-weight:bold">.</span>GETFILTER<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Country/Region Code&#34;<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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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><span style="color:#204a87;font-weight:bold">Filter</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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>RefreshBankNamesOlderThanToday@<span style="color:#0000cf;font-weight:bold">5</span><span style="color:#ce5c00;font-weight:bold">(</span>CountryRegionCode@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</span><span style="color:#000;font-weight:bold">;</span>ShowErrors@<span style="color:#0000cf;font-weight:bold">1002</span><span style="color:#f8f8f8;text-decoration:underline"> </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:#000;font-weight:bold">;</span>Timeout@<span style="color:#0000cf;font-weight:bold">1004</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>BankDataConvBank@<span style="color:#0000cf;font-weight:bold">1001</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#0000cf;font-weight:bold">1259</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ImpBankListExtDataHndl@<span style="color:#0000cf;font-weight:bold">1003</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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><span style="color:#0000cf;font-weight:bold">1289</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><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>CountryRegionCode<span style="color:#f8f8f8;text-decoration:underline"> </span>&lt;&gt;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>BankDataConvBank<span style="color:#ce5c00;font-weight:bold">.</span>SETFILTER<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Country/Region Code&#34;<span style="color:#000;font-weight:bold">,</span>CountryRegionCode<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>BankDataConvBank<span style="color:#ce5c00;font-weight:bold">.</span>SETFILTER<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Last Update Date&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;&lt;%1&#39;</span><span style="color:#000;font-weight:bold">,</span>TODAY<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></span><span style="display:flex;"><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>BankDataConvBank<span style="color:#ce5c00;font-weight:bold">.</span>FINDFIRST<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ImpBankListExtDataHndl<span style="color:#ce5c00;font-weight:bold">.</span>GetBankListFromConversionService<span style="color:#ce5c00;font-weight:bold">(</span>ShowErrors<span style="color:#000;font-weight:bold">,</span>CountryRegionCode<span style="color:#000;font-weight:bold">,</span>Timeout<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></span><span style="display:flex;"><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></span></code></pre></div><h2 id="nav-usages">NAV Usages</h2> <p>Bank name lookup on the Bank Account card for dynamically identifying the format to use to generate a bank-specific payment file.</p> <h2 id="ideas-for-improvement">Ideas for Improvement</h2> <p>Expose the refresh rate through a setup table to make it easily configurable without changing the code.</p>Docs: CaptionML on System Pageshttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/localizability/captionml-for-system-tables/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/localizability/captionml-for-system-tables/ <p>CaptionML should always be specified on a page field for a system table. By default, system tables do not have captions, so if you need to use them in the UI then captions need to be added.</p> <p>Bad code</p> <pre><code>... { 2 ;2 ;Field ; SourceExpr=Name } ... OBJECT Table 2000000000 User ... { 2 ; ;Name ;Text50 } </code></pre> <p>Good code</p> <pre><code>... { 2 ;2 ;Field ; CaptionML=ENU=Name; SourceExpr=Name } ... OBJECT Table 2000000000 User ... { 2 ; ;Name ;Text50 } </code></pre>Docs: CASE Actionhttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/case-actions/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/case-actions/ <p>A CASE action should start on a line after the possibility.</p> <p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">CASE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Letter<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">OF</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;A&#39;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Letter2<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:#4e9a06">&#39;10&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;B&#39;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Letter2<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:#4e9a06">&#39;11&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">CASE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Letter<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">OF</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;A&#39;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Letter2<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:#4e9a06">&#39;10&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;B&#39;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Letter2<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:#4e9a06">&#39;11&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div>Docs: Class Couplinghttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/class-coupling/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/class-coupling/ <p>Do not write functions that have high class coupling. This makes the code hard to maintain.</p> <p>Bad code</p> <pre><code>Any procedure / trigger that has class coupling of &gt; 30 </code></pre> <p>Good code</p> <pre><code>Any procedure / trigger that has class coupling of &lt;= 30\. Class coupling is computed by summing the unique instances of the following in a code block: - every unique usage of a complex C/AL data type (table, codeunit, etc) as 1\. - every unique usage of a DotNet type as 1\. </code></pre>Docs: Code of Conducthttps://alguidelines.dev/docs/navpatterns/4-get-involved/code-of-conduct/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/4-get-involved/code-of-conduct/ <p>Find below the rules to be used when disseminating or relating to the NAV Design Patterns.</p> <ol> <li>Only use materials published in text on the NAV Design Patterns Wiki site. If you received from us, any unpublished materials, please observe that they are subject to change and have not been approved for external use.</li> <li>When referencing a NAV Design Pattern, you must remember to also reference its author and company where the author is employed. You will find the author and his/her company at the beginning of each pattern, under the title.</li> <li>When referencing a NAV Design Patterns project, you must make it clear that this is a community project, driven by Microsoft, with multiple developers involved from both Microsoft and the community.</li> <li>When using published text content of NAV Design Patterns, do not alter the text in any way that was published on the Wiki site, unless is has been reviewed by the patterns team and signed off by someone at Microsoft in writing.</li> <li>If you have other materials which have not received explicit signoff in writing from me, where I have specifically stated that they are valid design patterns ready for publishing, please do not name them &ldquo;NAV Design Patterns&rdquo; (or anything similar). You are free to use your own content, but do not associate it in any way with NAV Design Patterns unless it is signed off in writing.</li> <li>If you do choose to use your own content, you must make it clear that it is not a NAV Design Pattern.</li> </ol>Docs: Colon usage in CASEhttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/colon-usage-in-case/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/colon-usage-in-case/ <p>The last possibility on a CASE statement must be immediately followed by a colon.</p> <p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">CASE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>DimOption<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">OF</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DimOption<span style="color:#000;font-weight:bold">::</span>&#34;Global Dimension 1&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DimValue<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Dimension Code&#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>GLSetup<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Global Dimension 1 Code&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">CASE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>DimOption<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">OF</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DimOption<span style="color:#000;font-weight:bold">::</span>&#34;Global Dimension 1&#34;<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DimValue<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Dimension Code&#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>GLSetup<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Global Dimension 1 Code&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div>Docs: Comments inside Curly Bracketshttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/comments-curly-brackets/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/comments-curly-brackets/ <p>Never use curly bracket comments. During development, the &ldquo;Block comment&rdquo; functionality can be used instead. However, in production code, block comments are not recommended.</p> <p>Bad code</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="display:flex;"><span>PeriodTxt<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>{Period}<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>Good code</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="display:flex;"><span>PeriodTxt<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// Period </span></span></span></code></pre></div><p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">PROCEDURE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MATRIX_OnAfterGetRecord@<span style="color:#0000cf;font-weight:bold">10</span><span style="color:#ce5c00;font-weight:bold">(</span>MATRIX_ColumnOrdinal<span style="color:#f8f8f8;text-decoration:underline"> </span><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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>{<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>ShowColumnName<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MatrixHeader<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MatrixRecords[MATRIX_ColumnOrdinal]<span style="color:#ce5c00;font-weight:bold">.</span>Name<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MatrixHeader<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MatrixRecords[MATRIX_ColumnOrdinal]<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">Code</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>}<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MatrixRecord<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MatrixRecords[MATRIX_ColumnOrdinal]<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>AnalysisValue<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>CalcAmt<span style="color:#ce5c00;font-weight:bold">(</span>ValueType<span style="color:#000;font-weight:bold">,</span>TRUE<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MATRIX_CellData[MATRIX_ColumnOrdinal]<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>AnalysisValue<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">PROCEDURE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MATRIX_OnAfterGetRecord@<span style="color:#0000cf;font-weight:bold">10</span><span style="color:#ce5c00;font-weight:bold">(</span>MATRIX_ColumnOrdinal<span style="color:#f8f8f8;text-decoration:underline"> </span><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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MatrixRecord<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MatrixRecords[MATRIX_ColumnOrdinal]<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>AnalysisValue<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>CalcAmt<span style="color:#ce5c00;font-weight:bold">(</span>ValueType<span style="color:#000;font-weight:bold">,</span>TRUE<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MATRIX_CellData[MATRIX_ColumnOrdinal]<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>AnalysisValue<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div>Docs: Comment Spacinghttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/comments-spacing/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/comments-spacing/ <p>Always start comments with // followed by one space character.</p> <p>Bad code</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="display:flex;"><span>RowNo<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:#0000cf;font-weight:bold">1000</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">//Move way below the budget </span></span></span></code></pre></div><p>Good code</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="display:flex;"><span>RowNo<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:#0000cf;font-weight:bold">1000</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// Move way below the budget </span></span></span></code></pre></div>Docs: Conditional Cascading Updatehttps://alguidelines.dev/docs/navpatterns/patterns/conditional-cascading-update/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/conditional-cascading-update/ <p><em>Originally by Jan Hoek at IDYN</em></p> <h2 id="abstract">Abstract</h2> <p>The Conditional Cascading Update pattern is used to intelligently populate fields whose values depend on other field values. In this pattern description, the field triggering the update will be called &ldquo;source field&rdquo;, and the depending field will be called &ldquo;target field&rdquo;.</p> <h2 id="description">Description</h2> <p>The value of one table field sometimes depends on the value of another field, typically following an application-defined transformation (note that we&rsquo;re talking about transformations of field values here. This has nothing to do with e.g. form transformation), such as conversion to uppercase, removal of certain characters etc.</p> <p>If the target field is non-editable, said transformation is usually the only way for the target field to receive new values, so no irreproducible information can be lost. However, if the target field is editable, the user may have cared enough to override the default (transformed) value, in which case revalidating the source field should not blindly replace the target field&rsquo;s value.</p> <h2 id="usage">Usage</h2> <p>In the OnValidate trigger of the source field, test if the target field value is either blank, or equal to the transformed value of the source field&rsquo;s previous contents. If it is, populate the target field&rsquo;s value with the transformed source field value. If it is not, do nothing (effectively preserving the value set by the user).</p> <h2 id="nav-specific-example">NAV Specific Example</h2> <p>In the base application, this pattern can be found in Search Name/Search Description fields, which are updated with the uppercase value from the corresponding Name/Description field when the latter is validated, only if the Search Name/Description in question is currently blank, or equal to the (uppercase equivalent) of the previous contents of the Name/Description field.</p> <p><a href="3124.T18_5F00_Name_5F00_OnValidate.png"><img src="3124.T18_5F00_Name_5F00_OnValidate.png" alt=" "></a></p> <p>In this particular case, the transformation between source and target fields is implicit and due to the different data types of the fields (text vs. code). Note how the field triggers of the Search Name field itself do not contain any logic linked to this pattern.</p> <h2 id="consequences">Consequences</h2> <p>There is a case when this pattern should not be used. If the target field is non-editable, this pattern will not add any value, since there won&rsquo;t be any user-overridden values to protect.</p>Docs: CONFIRMhttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/ux/confirm/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/ux/confirm/ <p>Always end CONFIRM with a question mark.</p> <p>Bad code</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="display:flex;"><span>ChangeAllOpenedEntriesQst@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TextConst</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;ENU=Do you want to change all open entries for every customer and vendor that are not blocked&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>CONFIRM<span style="color:#ce5c00;font-weight:bold">(</span>ChangeAllOpenedEntriesQst<span style="color:#000;font-weight:bold">,</span>TRUE<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></span></code></pre></div><p>Good code</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="display:flex;"><span>ChangeAllOpenedEntriesQst@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TextConst</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;ENU=Do you want to change all open entries for every customer and vendor that are not blocked?&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>CONFIRM<span style="color:#ce5c00;font-weight:bold">(</span>ChangeAllOpenedEntriesQst<span style="color:#000;font-weight:bold">,</span>TRUE<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></span></code></pre></div>Docs: Copy Documenthttps://alguidelines.dev/docs/navpatterns/patterns/copy-document/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/copy-document/ <p><em>By Bogdan Sturzoiu at Microsoft Development Center Copenhagen</em></p> <h2 id="abstract">Abstract</h2> <p>The goal of the Copy Document pattern is to create a replica of an existing open or closed document (posted or not posted), by moving the lines and, optionally, the header information from the source document to a destination document.</p> <h2 id="description">Description</h2> <p>Documents are widely used by most of our customers. Many times, a significant portion of these documents are similar to each other, either by sharing the same customer, vendor, type, or line structure. Being able to re-use a document as a base for creating a new one is therefore an important means of saving time.</p> <p>Other business scenarios require that a newly created document is applied to an existing document. For example, in returns management, a return order can be the reversal of an existing order and can therefore be copied from the original order. Other times, there is even a legal requirement to match the document to its source. For example, credit memos need to be applied to the originating Invoice.</p> <p>For these reasons, NAV supports the copying of documents as a method to re-use or link documents.</p> <p>The Copy Document functionality is used in the following situations:</p> <ul> <li>The user wants to create a new open sales document (Quote, Order, Blanket Order, Invoice, Return Order, Credit Memo) based on an existing posted or non-posted sales document (Quote, Blanket Order, Order, Invoice, Return Order, Credit Memo, Posted Shipment, Posted Invoice, Posted Return Receipt, Posted Credit Memo).</li> <li>The user wants to create a new open purchase document (Quote, Order, Blanket Order, Invoice, Return Order, Credit Memo) based on an existing posted or non-posted purchase document (Quote, Blanket Order, Order, Invoice, Return Order, Credit Memo, Posted Shipment, Posted Invoice, Posted Return Receipt, Posted Credit Memo).</li> <li>The user wants to create a new production order (Simulated, Planned, Firm Planned or Released) based on an existing production order (Simulated, Planned, Firm Planned, Released or Finished).</li> <li>The user wants to create a new assembly order based on an existing assembly document (Quote, Blanket Order, Order and Posted Order).</li> <li>The user wants to create a new service contract or quote based on an existing service contract or quote.</li> <li>The user wants to create all relevant return-related documents. For example, from a sales return order, the user can recreate the involved supply chain documentation, by copying the information upwards to a purchase return order (if the items need to be returned to the vendor), purchase order (if the items need to be reordered), and sales order (if the items need to be re-sent to the customer).</li> </ul> <p><strong>Note</strong></p> <ul> <li>Not all to and from combinations are allowed. For example, you can only copy to open document types, since the posted documents are not editable.</li> <li>The destination document needs to have the header fully created. For example, a Sales Order will need to have the Sell-To Customer No. populated.</li> </ul> <h2 id="usage">Usage</h2> <p>The Dynamics NAV application developer can take into account using the Copy Document design pattern when they have requirements such as:</p> <ul> <li>To provide a quick and efficient way of moving content from a document to another.</li> <li>To allow reusing the document history as a template for new documents.</li> <li>To allow linking of documents that need to be applied to each other.</li> </ul> <p>The Copy Document pattern involves the following entities:</p> <ol> <li> <p>Source document tables for document header and line. For example,Sales Header/Line.</p> </li> <li> <p>Destination document tables for document header and line.<br> <strong>Note:</strong> The source document header/line and destination document header/line tables do not need to be the same. For example, you can copy a Sales Shipment Header/Lines into a Sales Header/Lines.</p> </li> <li> <p>Copy Document engine: COD6620, Copy Document Mgt.</p> </li> <li> <p>Copy Document report for a specific document type. The report requires the following parameters:</p> </li> </ol> <ul> <li>Source Document Type</li> <li>Source Document No.</li> <li>Include Header (optional)</li> <li>Recalculate Lines (optional)</li> </ul> <p>Example: REP901, Copy Assembly Document</p> <p><a href="clip_image002.gif-750x0.png"><img src="clip_image002.gif-750x0.png" alt=" "></a></p> <h2 id="usage-sequence">Usage Sequence</h2> <p><strong>Precondition</strong>: The user creates a new destination document Header, filling up the required information.</p> <p><strong>Step 1</strong>: The user runs the Copy Document report (element no. 4), filling up the parameters:</p> <ul> <li>Source Document Type</li> <li>Source Document No.</li> <li>Include Header and/or Recalculate Lines (not all Copy Document reports have these).</li> </ul> <p><strong>Step 2</strong>: The report copies the information in the source tables (Header and Line) into the destination tables (Header and Line).</p> <p><strong>Post processing</strong>: The user performs additional editing of the destination document.</p> <p>The sequence flow of the pattern is described in the following diagram.</p> <p><a href="clip_image004.gif-750x0.png"><img src="clip_image004.gif-750x0.png" alt=" "></a></p> <p>Example: Copy Sales Document for Credit Memos.</p> <p>In the standard version of Microsoft Dynamics NAV, the Copy Document functionality is implemented in the Sales Credit Memo window as shown in the following section.</p> <hr> <p><strong>Precondition</strong>: The user enters data in PAGE44, Sales Credit Memo.</p> <p><a href="clip_5F00_image006.jpg"><img src="clip_5F00_image006.jpg" alt=" "></a></p> <p><strong>Step 1</strong>: The user runs REP292, Copy Sales Document from the Sales Credit Memo window, populating the required parameters. The Include Header and Recalculate Lines fields are selected.</p> <p><a href="clip_5F00_image008.jpg"><img src="clip_5F00_image008.jpg" alt=" "></a></p> <p><strong>Step 2</strong>: The Sales Credit Memo window is populated with information from the source sales document.</p> <p><a href="clip_5F00_image010.jpg"><img src="clip_5F00_image010.jpg" alt=" "></a></p> <p><strong>Post processing</strong>: The user can now do additional editing of the sales credit memo.</p> <h1 id="nav-implementations">NAV Implementations</h1> <ol> <li>Copy Sales Document (REP292)</li> <li>Copy Purchase Document (REP492)</li> <li>Copy Service Document (REP5979)</li> <li>Copy Assembly Document (REP901)</li> </ol> <div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"> <iframe src="https://www.youtube.com/embed/aTiwroXwW0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" allowfullscreen title="YouTube Video"></iframe> </div>Docs: Create Data from Templateshttps://alguidelines.dev/docs/navpatterns/patterns/create-data-from-templates/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/create-data-from-templates/ <p><em>Originally by Nikola Kukrika at Microsoft Development Center Copenhagen</em></p> <h2 id="abstract">Abstract</h2> <p>For many records, such as Items, Customers, and Vendors, users have to enter the same sets of data again and again. This is tedious, error-prone (users forget to enter a field or they choose the wrong group), and difficult to learn for some users.</p> <p>We can group sets of data as templates to speed up and simplify the process of entering data in Microsoft Dynamics NAV. For example, the process of creating a new customer could be simplified so that users only have to enter information that is specific for every individual customer, e.g. Name and Address/Contact.</p> <h2 id="description">Description</h2> <p>This pattern solves the problem of creating new records based on their type. You should use it whenever there is a large set of data that could be grouped in a meaningful way.</p> <p>In Microsoft Dynamics NAV 2013 R2, we have extended the Configuration Templates feature so that templates can be used in different languages than the language they were created in. We have also added the ability to set related templates so that related records can be inserted, such as dimensions for customers, items, and vendors.</p> <p>The pattern consists of two parts:</p> <p>1. Using templates to create new records or applying templates to existing records</p> <p>2. Defining and updating existing templates</p> <h2 id="usage">Usage</h2> <p><a href="4118.Picture1.png"><img src="4118.Picture1.png" alt=" "></a></p> <p>Using the patterns involves three steps.</p> <ol> <li> <p>As a first step, we must insert a record. This can be done either through C/AL code or by letting the user create a record using the <strong>New</strong> action.</p> </li> <li> <p>After the record is created, we must apply the template. This is done by using the <strong>UpdateRecord</strong> function in the <strong>Config. Template Management</strong> codeunit (8612).</p> </li> </ol> <p><strong>Config. Template Lines</strong> records reference one <strong>Config. Template Header</strong> record (lines pattern). The lines can be of type:</p> <ul> <li><strong>Field</strong> - Stores a field value that will be applied to the record</li> <li><strong>Related</strong> Template &ndash; References a Config. Template Header record for a related template.</li> </ul> <p>The <strong>UpdateRecord</strong> function applies values to the record one line at the time. One of the requirements was to be possible to use configuration templates in different language/regional settings than the template was created in.</p> <p>To support this scenario, when applying the <strong>Config. Template Line</strong> record, <strong>GLOBALLANGUAGE</strong> is set to the language ID of the field. This is important because the default value is stored as text, so we need to use the same formatting that NAV was running on when the template was created. Otherwise, data types, such as Boolean, Date, etc., will raise validation errors.</p> <p>Any updates to a <strong>Config. Template Line</strong> record will automatically update the language ID to the current one. Since lines are applied one by one, it is supported to have lines with different language IDs belonging to the same template.</p> <ol start="3"> <li>After we have applied the template to the record, we can insert related templates. For example, when you insert an item, you may want to insert dimensions as well. You must implement the logic to apply or then modify the related templates, since this depends on the logic and the relationship between the records. Lines with <strong>Type = Related Template</strong> are used to reference related templates.</li> </ol> <p>Code example (Insert a record, apply a template, and insert the related templates):</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="display:flex;"><span><span style="color:#8f5902;font-style:italic">// First insert a record Customer.INSERT(TRUE); </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#8f5902;font-style:italic">// Apply a template RecRef.GETTABLE(Customer); </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>ConfigTemplateMgt<span style="color:#ce5c00;font-weight:bold">.</span>UpdateRecord<span style="color:#ce5c00;font-weight:bold">(</span>ConfigTemplateHeader<span style="color:#000;font-weight:bold">,</span>RecRef<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></span><span style="display:flex;"><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>Customer<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#8f5902;font-style:italic">// Insert Dimensions -- related templates </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>MiniDimensionsTemplate<span style="color:#ce5c00;font-weight:bold">.</span>InsertDimensionsFromTemplates<span style="color:#ce5c00;font-weight:bold">(</span>ConfigTemplateHeader<span style="color:#000;font-weight:bold">,</span>Customer<span style="color:#ce5c00;font-weight:bold">.</span>&#34;No.&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#204a87;font-weight:bold">DATABASE</span><span style="color:#000;font-weight:bold">::</span>Customer<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></span></code></pre></div><p>Code to insert related templates (dimensions):</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">FUNCTION</span><span style="color:#f8f8f8;text-decoration:underline"> </span>InsertDimensionsFromTemplates<span style="color:#ce5c00;font-weight:bold">(</span>ConfigTemplateHeader<span style="color:#f8f8f8;text-decoration:underline"> </span><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>MasterRecordNo<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Code</span>[<span style="color:#0000cf;font-weight:bold">20</span>]<span style="color:#000;font-weight:bold">;</span>TableID<span style="color:#f8f8f8;text-decoration:underline"> </span><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></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#8f5902;font-style:italic">// There are multiple records (multiple dimensions per master record) </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// We have to set filter </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateLine<span style="color:#ce5c00;font-weight:bold">.</span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Type</span><span style="color:#000;font-weight:bold">,</span>ConfigTemplateLine<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">Type</span><span style="color:#000;font-weight:bold">::</span>&#34;Related Template&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateLine<span style="color:#ce5c00;font-weight:bold">.</span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Data Template Code&#34;<span style="color:#000;font-weight:bold">,</span>ConfigTemplateHeader<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">Code</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>ConfigTemplateLine<span style="color:#ce5c00;font-weight:bold">.</span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateHeader<span style="color:#ce5c00;font-weight:bold">.</span>GET<span style="color:#ce5c00;font-weight:bold">(</span>ConfigTemplateLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Template Code&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// Ensure that the table where the template belongs to is Dimensions </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// We could have other related templates </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></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>ConfigTemplateHeader<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Table ID&#34;<span style="color:#f8f8f8;text-decoration:underline"> </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>&#34;Default Dimension&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>InsertDimensionFromTemplate<span style="color:#ce5c00;font-weight:bold">(</span>ConfigTemplateHeader<span style="color:#000;font-weight:bold">,</span>MasterRecordNo<span style="color:#000;font-weight:bold">,</span>TableID<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateLine<span style="color:#ce5c00;font-weight:bold">.</span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#8f5902;font-style:italic">// Create a new Dimensions Record and link it to the Master Record </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#204a87;font-weight:bold">FUNCTION</span><span style="color:#f8f8f8;text-decoration:underline"> </span>InsertDimensionFromTemplate<span style="color:#ce5c00;font-weight:bold">(</span>ConfigTemplateHeader<span style="color:#f8f8f8;text-decoration:underline"> </span><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>MasterRecordNo<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Code</span>[<span style="color:#0000cf;font-weight:bold">20</span>]<span style="color:#000;font-weight:bold">;</span>TableID<span style="color:#f8f8f8;text-decoration:underline"> </span><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></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span>DefaultDimension<span style="color:#ce5c00;font-weight:bold">.</span>INIT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DefaultDimension<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>MasterRecordNo<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DefaultDimension<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Table ID&#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>TableID<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DefaultDimension<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Dimension Code&#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>GetDefaultDimensionCode<span style="color:#ce5c00;font-weight:bold">(</span>ConfigTemplateHeader<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DefaultDimension<span style="color:#ce5c00;font-weight:bold">.</span>INSERT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>DefaultDimension<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ConfigTemplateMgt<span style="color:#ce5c00;font-weight:bold">.</span>UpdateRecord<span style="color:#ce5c00;font-weight:bold">(</span>ConfigTemplateHeader<span style="color:#000;font-weight:bold">,</span>RecRef<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></span><span style="display:flex;"><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>DefaultDimension<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></span></code></pre></div><p><strong>To surface the action in the product, you have three options:</strong></p> <ol> <li><strong>Recommended</strong> - Implement a separate action called <strong>New from Template</strong>.</li> <li><strong>Optional</strong> - Implement the apply template function on the document itself. This is especially good in scenarios where users are allowed to change the template.</li> <li><strong>Alternative</strong> - Remove the new action by configuration or set Insert Allowed to FALSE on the list (this will block the creation of new records from the lookup). Implement an application action named <strong>New</strong> and tie it to your code.</li> </ol> <p><strong>Note:</strong> In Microsoft Dynamics C5 2014, we chose to remove the <strong>New</strong> action with configuration since we wanted to promote the functionality and avoid the confusion in having too many options. However this might be difficult to maintain with a larger set of pages.</p> <p><strong>To view or edit templates, you have two options:</strong></p> <ol> <li>Use the <strong>Config. Template List</strong> table (8620) and the <strong>Config. Template Header Card</strong> table (8618).</li> </ol> <p>This is a generic solution that is not very usable and is error-prone (no lookups, checks for length, table relation checks, etc.) The default value is a text field of 250 characters, which might be much more than the field length, and may lead to validation errors when used. Users will most likely not be able to use this page.</p> <p><a href="2816.Picture3.png"><img src="2816.Picture3.png" alt=" "></a></p> <p>2. Implement custom pages resembling the document.</p> <p>This is optional if you want to enable the users to create and modify templates. In C5 2014, we created temporary tables with the same fields as the main record. Based on this temporary record, we built a page that resembles a document.</p> <p>Example of the <strong>Customer Template</strong> page:</p> <p><a href="7271.Picture4.png"><img src="7271.Picture4.png" alt=" "></a></p> <p>The goals of this solution were:</p> <ul> <li>To make the setup page resemble a document page so that it is easy to use with basic validation and lookups.</li> <li>To have only one place to store templates and maintain only one business logic for applying them, namely in the <strong>Configuration Template Header</strong> table.</li> <li>To avoid any lateral effects of doing validation on the temporary master record. Doing validation on fields, even though the record itself is temporary, could permanently modify other data in the database. For example, if you insert a new record in the <strong>Customer</strong> table, even in a temporary table, a Contact record is created, which will not be temporary.</li> <li>Testability: It is easy to test through RecordRef that the template table matches the main table. We can compare field lengths, data types, table relations, etc. The test is able to detect that they are out of sync, so it is easy to prevent errors.</li> </ul> <p>One example in the product is the <strong>Mini Customer Template</strong> table (1300).</p> <p>The table itself contains very little code. OnModify, OnInsert, and OnDelete triggers update the <strong>Configuration Header</strong> and <strong>Configuration Lines</strong> tables. The following functions in the <strong>Config. Template Management</strong> codeunit (8612), are used for this:</p> <ul> <li>ConfigTemplateManagement.CreateConfigTemplateAndLines</li> <li>ConfigTemplateManagement.UpdateConfigTemplateAndLines</li> <li>ConfigTemplateManagement.DeleteRelatedTemplates</li> </ul> <p>The CreateFieldRefArray function is used as an interface function on all the temporary template tables. It builds data to be read/written to the configuration templates.</p> <p>To further enhance the usability, we have provided the following additional functionality:</p> <ul> <li>Create a template from the existing record: The user opens an existing record and creates a template from that record. All the fields that are defined in the CreateFieldRefArray function are used to create the new template.</li> <li>Templates list: This page is used by users to select templates or create new ones. Depending on which templates they are working on, we show different template cards.</li> </ul> <h2 id="nav-specific-example">NAV Specific Example</h2> <p>In C5 2014, this is the workflow:</p> <p>The user opens the <strong>Customers List</strong> window and selects <strong>New</strong></p> <p><a href="4341.Picture4.png"><img src="4341.Picture4.png" alt=" "></a></p> <p>From this page, the user can view the template, edit it, or create a new one. Selecting a template will populate the customer card and open a new record. From the existing record, the user has options to save as a template or opening a list of templates to maintain available templates. Selecting a template will populate the customer card and open a new record. From the existing record, the user has options to save as a template or opening a list of templates to maintain available templates.</p> <p><a href="3482.Picture-5.png"><img src="3482.Picture-5.png" alt=" "></a></p> <p>From the <strong>Customer Card Template</strong> window, we can invoke the <strong>Dimensions</strong> action, through which we can define the dimensions that will be inserted together with the template:</p> <p><a href="2134.Picture6.png"><img src="2134.Picture6.png" alt=" "></a></p> <h2 id="nav-usages">NAV Usages</h2> <p>This pattern is used in Microsoft Dynamics C5 2014 in the following objects:</p> <ul> <li> <p>Temporary template tables:</p> <ul> <li><strong>Mini Customer Template</strong> table (1300)</li> <li><strong>Mini Item Template</strong> table (1301)</li> <li><strong>Mini Dimensions Template</strong> table(1302)</li> <li><strong>Mini Vendor Template</strong> table (1303)</li> </ul> </li> <li> <p>Pages to define templates:</p> <ul> <li><strong>Mini Customer Template Card</strong> page (1341)</li> <li><strong>Mini Item Template Card</strong> page (,1342)</li> <li><strong>Mini Dimensions Template List</strong> page (1343)</li> <li><strong>Mini Vendor Template Card</strong> page (1344)</li> </ul> </li> <li> <p>Pages that use the templates:</p> <ul> <li><strong>Mini Customer List</strong> page (1301)</li> <li><strong>Mini Item List</strong> page ( 1303)</li> <li><strong>Mini Vendor List</strong> page (1331)</li> </ul> </li> </ul> <p>In the standard version of Microsoft Dynamics NAV, we use the <strong>Apply Template</strong> action on the following pages:</p> <ul> <li><strong>Customer Card</strong> page (21)</li> <li><strong>Vendor Card</strong> page (26)</li> <li><strong>Item Card</strong> page (30)</li> <li><strong>Resource Card</strong> page (, 76)</li> <li>Other similar cards.</li> </ul> <h2 id="ideas-for-improvement">Ideas for improvement</h2> <p>Implement the solution in the standard version of Microsoft Dynamics NAV and extend the Apply Template functionality to insert dimensions.</p> <p>It is possible that users end up with a large number of templates if they need many different data combinations. An improvement could be to split templates into smaller groups, grouping only part of the fields that are related, and then apply only these.</p> <div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"> <iframe src="https://www.youtube.com/embed/F0CTvoyKSmI" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" allowfullscreen title="YouTube Video"></iframe> </div>Docs: Create URLs to NAV Clientshttps://alguidelines.dev/docs/navpatterns/patterns/create-urls-to-nav-clients/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/create-urls-to-nav-clients/ <p><em>By Mike Borg Cardona and Bogdana Botez at Microsoft Development Center Copenhagen</em></p> <h2 id="abstract">Abstract</h2> <p>This article illustrates NAV platform functionality to be used by C/AL developers.</p> <p>The URL builder function, GETURL, is released in Microsoft Dynamics NAV 2013 R2 to reduce coding time for developers who need to create various URL strings to run application objects in either the win client, the web client, or on web services. In addition, the GETURL function makes multitenancy features more transparent to C/AL developers.</p> <h2 id="description">Description</h2> <p>Ever had to construct win client URLs like the one below?</p> <p>dynamicsnav://myserver:7046/myInstance/myCompany/runpage?page=26</p> <p>Today, Microsoft Dynamics NAV also provides a web client. This means that you must update your code to construct web client URLs too. What about multitenancy? The URL Builder should know if it is running in a multitenant setup and it should know how to choose the right tenant. What about maintaining this code?</p> <p>The good news is that GETURL has been introduced to handle all URL building for you.</p> <p>GETURL automatically handles:</p> <ul> <li>Multitenancy</li> <li>Correct URL format for each client</li> <li>Publicly accessible hostnames.</li> </ul> <h2 id="usage">Usage</h2> <p>The format is:</p> <p>[String :=] GETURL(ClientType[, Company][, Object Type][, Object Id][, Record])</p> <p>Where:</p> <ul> <li><strong>Client Type</strong> can be: Current, Default, Windows, Web, SOAP, or OData. This enables a range of scenarios for the C/AL developer, such as moving to the web client without changing code to decide where the URL should point to. This is done either by setting Client Type to Current, and just ensuring that web is used to invoke the link creation, or by setting Client Type to Default and changing its value to Web when it is ready to move to the web platform.</li> <li><strong>Object Type</strong> and <strong>Object ID</strong> define the type of the application object to run (Table, Page, Report, Codeunit, Query, or XMLport) and its ID.</li> <li><strong>Record</strong> specifies the actual data to run the URL on, such as:</li> </ul> <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="display:flex;"><span>Vendor<span style="color:#ce5c00;font-weight:bold">.</span>GET<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Account No.&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>GETURL<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">CLIENTTYPE</span><span style="color:#000;font-weight:bold">:</span>WEB<span style="color:#000;font-weight:bold">,</span>COMPANYNAME<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">OBJECTTYPE</span><span style="color:#000;font-weight:bold">::</span><span style="color:#204a87;font-weight:bold">Page</span><span style="color:#000;font-weight:bold">,</span><span style="color:#0000cf;font-weight:bold">27</span><span style="color:#000;font-weight:bold">,</span>Vendor<span style="color:#ce5c00;font-weight:bold">) </span></span></span></code></pre></div><p><strong>Note</strong>: It is currently not possible to set filters on the record that you sent as a last parameter to the GETURL function. However, it is possible to write your own code to compute and append the filter string to the URL that is created by the GETURL function.</p> <p>The server name and instance are extracted automatically by GETURL and do not need to be specified by the C/AL developer. Furthermore, the multitenancy setup is transparent to the C/AL developer. No multitenancy parameters are specified when you call GETURL, because the function knows from the server setup if it is running in a multitenant environment and if so, it will add a string like &ldquo;&amp;tenant=MyTenant&rdquo; to the URL.</p> <h2 id="when-to-use">When to Use</h2> <p>The GETURL function can generally be used every time a URL must be created. The following are some scenarios where the function is particularly useful.</p> <ul> <li>Document approvals. For more information, see the &ldquo;NAV Usage Example&rdquo; section.</li> <li>Reports containing drill-down links. (Beware of the resource cost of adding a new URL element to the Report dataset.)</li> <li>When planning to write code for, or migrate to, various display targets (Microsoft Dynamics NAV Windows client, Microsoft Dynamics NAV web client, Microsoft Dynamics NAV web services) without having to explicitly specify which client to use.</li> </ul> <h2 id="examples-of-usage">Examples of Usage</h2> <p>The following are examples of calls to GETURL and their corresponding return value:</p> <table> <thead> <tr> <th>Command</th> <th>URL</th> </tr> </thead> <tbody> <tr> <td>GETURL(CLIENTTYPE::Win)</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71//</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web)</td> <td>https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData)</td> <td>http://MyServer:7048/DynamicsNAV71/OData</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP)</td> <td>http://MyServer:7047/DynamicsNAV71/WS/Services</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Current) ie. When running this code on a Win client session</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71//</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Default) ie. When the Server config key DefaultClient is set to Windows</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71//</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,COMPANYNAME)</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,&rsquo;')</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71//</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,&lsquo;NONEXISTING Corp&rsquo;)</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/NONEXISTING Corp/</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,COMPANYNAME)</td> <td>https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,&rsquo;')</td> <td>https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,&lsquo;NONEXISTING Corp&rsquo;)</td> <td>https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=NONEXISTING Corp</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME)</td> <td>http://MyServer:7048/DynamicsNAV71/OData/Company(&lsquo;CRONUS&rsquo;)</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,&rsquo;')</td> <td>http://MyServer:7048/DynamicsNAV71/OData</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,&lsquo;NONEXISTING Corp&rsquo;)</td> <td>http://MyServer:7048/DynamicsNAV71/OData/Company(&lsquo;NONEXISTING Corp&rsquo;)</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME)</td> <td>http://MyServer:7047/DynamicsNAV71/WS/CRONUS/Services</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,&rsquo;')</td> <td>http://MyServer:7047/DynamicsNAV71/WS/Services</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,&lsquo;NONEXISTING Corp&rsquo;)</td> <td>http://MyServer:7047/DynamicsNAV71/WS/NONEXISTING Corp/Services</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Table,27)</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runtable?table=27</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Page,27)</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runpage?page=27</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Report,6)</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runreport?report=6</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Codeunit,5065)</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runcodeunit?codeunit=5065</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Query,9150)</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runquery?query=9150</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::XmlPort,5150)</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runxmlport?xmlport=5150</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Page,27) ie. When the Web Service is published</td> <td>http://MyServer:7048/DynamicsNAV71/OData/Company(&lsquo;CRONUS&rsquo;)/PAG27Vendors</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Query,9150) ie. When the Web Service is published</td> <td>http://MyServer:7048/DynamicsNAV71/OData/Company(&lsquo;CRONUS&rsquo;)/QUE9150MyCustomers</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Page,27)Â ie. When the Web Service is published</td> <td>http://MyServer:7047/DynamicsNAV71/WS/CRONUS/Page/PAG27Vendors</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Codeunit,5065) ie. When the Web Service is published</td> <td>http://MyServer:7047/DynamicsNAV71/WS/CRONUS/Codeunit/COD5065EmailLogging</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Page,27,record) List Page</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runpage?page=27&amp;bookmark=23;FwAAAAJ7/0kAQwAxADAAMwAw</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Page,26,record) Card Page</td> <td>dynamicsnav://MyServer:7046/DynamicsNAV71/CRONUS/runpage?page=26&amp;bookmark=23;FwAAAAJ7/0kAQwAxADAAMwAw</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Page,27,record) List Page</td> <td>https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS&amp;page=27&amp;bookmark=23;FwAAAAJ7/0kAQwAxADAAMwAw</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Page,26,record) Card Page</td> <td>https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS&amp;page=26&amp;bookmark=23;FwAAAAJ7/0kAQwAxADAAMwAw</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Page,27,record)</td> <td>http://MyServer:7048/DynamicsNAV71/OData/Company(&lsquo;CRONUS&rsquo;)/PAG27Vendors(&lsquo;IC1030&rsquo;)</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Page,27)</td> <td>https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS&amp;page=27</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Report,6)</td> <td>https://navwebsrvr:443/DynamicsNAV71_Instance1/Webclient?company=CRONUS&amp;report=6</td> </tr> </tbody> </table> <p>If the GETURL function is called with invalid parameters, it will return an empty string. In that case, you can find the related error text by calling the GETLASTERRORTEXT function.</p> <table> <thead> <tr> <th>Function Call</th> <th>Error Message</th> </tr> </thead> <tbody> <tr> <td>GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Table,27)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Codeunit,5065)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::Query,9150)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::Web,COMPANYNAME,OBJECTTYPE::XmlPort,5150)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Table,27)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Page,27)</td> <td>The Page object, 27, that is specified for the GetUrl function has not been published in the Web Services table.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Report,6)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Codeunit,5065)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::Query,9150)</td> <td>The Query object, 9150, that is specified for the GetUrl function has not been published in the Web Services table.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::OData,COMPANYNAME,OBJECTTYPE::XmlPort,5150)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Table,27)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Page,27)</td> <td>The Page object, 27, that is specified for the GetUrl function has not been published in the Web Services table.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Report,6)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Codeunit,5065)</td> <td>The Codeunit object, 5065, that is specified for the GetUrl function has not been published in the Web Services table.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Query,9150)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::XmlPort,5150)</td> <td>The specified object type parameter for the GetUrl function is not valid.</td> </tr> <tr> <td>GETURL(CLIENTTYPE::SOAP,COMPANYNAME,OBJECTTYPE::Page,27,record)</td> <td>You cannot specify a record parameter for the GetUrl function when the object type is SOAP</td> </tr> </tbody> </table> <h2 id="nav-specific-example">NAV Specific Example</h2> <p>The following example shows how to use the GETURL function in codeunit 440 to ensure that the notification mail in Document Approvals can link to both the Microsoft Dynamics NAV Windows client and the Microsoft Dynamics NAV web client:</p> <p><a href="1778.url1.jpg"><img src="1778.url1.jpg" alt=" "></a></p> <p>This resulting UI looks as follows.</p> <p><a href="7802.url2.jpg"><img src="7802.url2.jpg" alt=" "></a></p> <p>The first link opens the approval document in the Microsoft Dynamics NAV Windows client. The second link (Web view) opens the same document in the Microsoft Dynamics NAV web client.</p>Docs: Creating Custom Chartshttps://alguidelines.dev/docs/navpatterns/patterns/creating-custom-charts/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/creating-custom-charts/ <p><em>Originally by Nikola Kukrika at Microsoft Development Center Copenhagen</em></p> <h2 id="abstract">Abstract</h2> <p>The goal of this solution is to enable you to:</p> <ol> <li>Use charts in the web client.</li> <li>Create charts with custom functionality.</li> </ol> <h2 id="description">Description</h2> <p>This pattern enables you to implement a business chart (Specific Chart type) in a way that is maintainable and reusable on other pages. This also enables you to provide specific functionality that is not possible with the Generic Chart type and it enables you to show charts in the web client.</p> <p>The Business Chart add-in is a special because it is a combination of .NET and Javascript add-ins depending on the display target. In the web client, it renders a JavaScript control, while in the win client, it renders a .Net control. Because of this behavior, you can expect minor differences in how the chart is presented in the win client versus in the web client. Note that this implementation is specific to NAV platform code, because it is not possible to create add-ins that combines .NET and JavaScript by using a framework API.</p> <p><a href="5153.Picture1.png"><img src="5153.Picture1.png" alt=" "></a></p> <p>Example of the same chart in the win client:</p> <p><a href="1411.Picture2.png"><img src="1411.Picture2.png" alt=" "></a></p> <p>The most obvious differences in chart rendering in the two clients are: Slightly different line heights, slightly different chart height, legends in web-client charts can be used as toggle filters to show/hide groups (this is not possible in the win client).</p> <h3 id="implementation-overview">Implementation Overview</h3> <p><a href="1781.Picture5.png"><img src="1781.Picture5.png" alt=" "></a></p> <h3 id="add-in-buffer-table">Add-in Buffer Table</h3> <p>This table is used to encapsulate the logic of the Business Chart Add-in. The table handles the following logic:</p> <ul> <li>Storing chart values and conversion from .NET to C/AL and vice versa</li> <li>Handling of captions: We must use C/AL to provide multilanguage text in add-ins. In addition, the multilanguage text must be encapsulated in a single place, because we pass/read the same dataset from/to the add-in.</li> <li>DrillDown logic</li> <li>Other helper data related functions, for displaying date, periods, etc.[Bogdana1] [NK2] [NK3]</li> </ul> <p><strong>Note:</strong> It is recommended that you reuse the <strong>Business Chart Buffer table</strong> (485) as a buffer table or extend. It is a generic table which should cover most of the use cases. Implement a new buffer table only if this table does not meet your needs.</p> <h3 id="cardpart-page">CardPart page</h3> <p>The CardPart page hosts the Business Chart add-in and must use the add-in buffer table as a source table.</p> <p>On the page, you must implement the following triggers:</p> <ul> <li><strong>AddInReady</strong> &ndash; Executed when the page is done rendering. Used to initialize the add-in.</li> <li><strong>DataPointClicked</strong> &ndash; Single-click on an element on the chart.</li> <li><strong>DataPointDoubleClicked</strong> &ndash; Double-click on an element on the chart</li> </ul> <p>The CardPart usually contains a StatusText variable to provide more information about the chart or dataset and a set of actions to control the chart.</p> <p>The most commonly used actions are:</p> <ul> <li><strong>Select Chart</strong>, <strong>Previous Chart</strong>, <strong>Next Chart</strong></li> <li><strong>Set Period</strong>, <strong>Work Date</strong></li> <li>Actions to filter the data set</li> <li><strong>Refresh</strong></li> <li><strong>Chart Information</strong> &ndash; a tooltip with a description of the chart and how data is calculated.</li> </ul> <h3 id="optional-preserving-user-personalization">Optional: Preserving User Personalization</h3> <p>One of the most common functionalities is personalization. If the chart can be customized by the user, you should store the settings that the user has entered and apply them the next time the chart is loaded.</p> <p>To do this, you need the following:</p> <ul> <li>A setup record to store the data. You can use the <strong>Business Chart User Setup</strong> table (487) or create a new setup table if you need to store more information.</li> <li>A management codeunit to write/apply the settings to the chart and to encapsulate other logic. Since we should not write code on pages, the code for the actions and other logic that does not apply to the setup record should go in this codeunit.</li> <li>Setup pages where users can customize how the chart is shown and set different settings.</li> </ul> <p>The relation between the components is visualized in the following diagram:</p> <p><a href="0246.Picture6.png"><img src="0246.Picture6.png" alt=" "></a></p> <h3 id="optional-show-multiple-charts-within-a-single-cardpart">Optional: Show Multiple Charts within a Single CardPart</h3> <p>This option is useful on a Role Center where you want to show multiple charts using different datasets within a single part. In that case, you need a record to store the last chart selection, the setup records, and code units for separate charts.</p> <p>See, for example, the implementation of the <strong>Mini Generic Chart</strong> page (1390), which uses <strong>MiniChartManagment</strong> CodeUnit to manage separate management codeunits for charts and their setup records. The last selected chart is stored in a separate table, <strong>Mini Chart Definition</strong> (1310).</p> <p><a href="1803.Picture7.png"><img src="1803.Picture7.png" alt=" "></a></p> <h2 id="usage">Usage</h2> <p>To implement the pattern, create a new ChartPart and set the source table to <strong>Business Chart Buffer</strong>.</p> <p>Add a field named <strong>BusinessChart</strong> and set the ControlAddIn property to Microsoft.Dynamics.Nav.Client.BusinessChart.</p> <p>Then implement the AddInReady event. This event is executed when the page is done rendering. Code within this method must call the Update method from the <strong>Business Chart Buffer</strong> table, Update(CurrPage.BusinessChart) to initialize the chart and assign initial values.</p> <p>If you need a setup record and codeunit, then it is a good idea to encapsulate this logic within a method.</p> <h3 id="nav-specific-example-1">NAV Specific Example 1</h3> <p>Implementation of the <strong>Finance Performance Chart</strong> page (762)</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="display:flex;"><span>BusinessChart<span style="color:#000;font-weight:bold">::</span>AddInReady<span style="color:#ce5c00;font-weight:bold">() </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>UpdateChart<span style="color:#ce5c00;font-weight:bold">(</span>Period<span style="color:#000;font-weight:bold">::</span>&#34; &#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>UpdateChart<span style="color:#ce5c00;font-weight:bold">(</span>Period<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;,Next,Previous&#39;</span><span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>MoveAndUpdateChart<span style="color:#ce5c00;font-weight:bold">(</span>Period<span style="color:#000;font-weight:bold">,</span><span style="color:#0000cf;font-weight:bold">0</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>MoveAndUpdateChart<span style="color:#ce5c00;font-weight:bold">(</span>Period<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;,Next,Previous&#39;</span><span style="color:#000;font-weight:bold">;</span>Move<span style="color:#f8f8f8;text-decoration:underline"> </span><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></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>AccSchedChartManagement<span style="color:#ce5c00;font-weight:bold">.</span>GetSetupRecordset<span style="color:#ce5c00;font-weight:bold">(</span>AccountSchedulesChartSetup<span style="color:#000;font-weight:bold">,</span>AccountSchedulesChartSetup<span style="color:#ce5c00;font-weight:bold">.</span>Name<span style="color:#000;font-weight:bold">,</span>Move<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>AccSchedChartManagement<span style="color:#ce5c00;font-weight:bold">.</span>UpdateData<span style="color:#ce5c00;font-weight:bold">(</span>Rec<span style="color:#000;font-weight:bold">,</span>Period<span style="color:#000;font-weight:bold">,</span>AccountSchedulesChartSetup<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>Update<span style="color:#ce5c00;font-weight:bold">(</span>CurrPage<span style="color:#ce5c00;font-weight:bold">.</span>BusinessChart<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>StatusText<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>GetCurrentSelectionText<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Period Filter Start Date&#34;<span style="color:#000;font-weight:bold">,</span>&#34;Period Filter End Date&#34;<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></span></code></pre></div><p>In the MoveAndUpdateChart method, the AccSchedChartManagement codeunit gets a setup record and updates it if necessary. Then, it initializes the chart with setup data and sets the StatusText to show the period for which data is displayed. The same method is used by the actions to move and update the chart so that there is no code duplication.</p> <p>The following code is used to implement <strong>DataPointClicked</strong></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="display:flex;"><span>BusinessChart<span style="color:#000;font-weight:bold">::</span>DataPointClicked<span style="color:#ce5c00;font-weight:bold">(</span>point<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DotNet</span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Microsoft.Dynamics.Nav.Client.BusinessChart.BusinessChartDataPoint&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>SetDrillDownIndexes<span style="color:#ce5c00;font-weight:bold">(</span>point<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>AccSchedChartManagement<span style="color:#ce5c00;font-weight:bold">.</span>DrillDown<span style="color:#ce5c00;font-weight:bold">(</span>Rec<span style="color:#000;font-weight:bold">,</span>AccountSchedulesChartSetup<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></span></code></pre></div><p>SetDrillDownindexes is a method from the <strong>Business Chart Buffer</strong> table that maps the DotNet point variable to C/AL data, so it must be used. The next method that you must implement is the action to be performed on Drilldown.</p> <p>The <strong>DataPointDoubleClicked</strong> trigger has the same implementation logic as the DataPointClicked trigger.</p> <h3 id="nav-specific-example-2">NAV Specific Example 2</h3> <p>Implementation of chart part 1390 on the <strong>Small Business Role Center</strong> page (9022)</p> <p><a href="1541.Picture7.png"><img src="1541.Picture7.png" alt=" "></a></p> <p>This chart part contains data from multiple charts within a single part. The <strong>Status Text</strong> field shows the name of the chart and the current period. Users can browse through the charts with <strong>Next Chart</strong> and <strong>Previous Chart</strong> or use <strong>Select Chart</strong> to choose from a list of available charts.</p> <p><a href="2553.Picture8.png"><img src="2553.Picture8.png" alt=" "></a></p> <p>On this dialog, users can choose if a chart should be enabled or disabled. If the chart is not enabled, it will be skipped on the <strong>Previous Chart</strong> and <strong>Next Chart</strong> actions. Charts used by this part use different codeunits and setup records. If the user changes the selected chart, this option will be saved and applied next time role center is opened.</p> <p>Users can also change the period length.</p> <p><a href="5545.Picture9.png"><img src="5545.Picture9.png" alt=" "></a></p> <p>Choosing the <strong>Chart Information</strong> button opens a short description of the chart.</p> <p><a href="5582.Picture10.png"><img src="5582.Picture10.png" alt=" "></a></p> <h2 id="nav-usages">NAV Usages</h2> <p>Implementation of multiple charts within a single part:</p> <ul> <li>Page 1390, <strong>Mini Generic Chart</strong></li> </ul> <p>Charts that use a setup record and select the chart with <strong>Customize Chart Setup</strong> pages:</p> <ul> <li>Page 772, <strong>Inventory Performance</strong></li> <li>Page 771, <strong>Purchase Performance</strong></li> <li>Page 770, <strong>Sales Performance</strong></li> <li>Page 762, <strong>Finance Performance</strong></li> </ul> <p>Chart that uses the <strong>Business Chart User Setup</strong> table:</p> <ul> <li>Page 768, <strong>Aged Acc. Receivable Chart</strong></li> </ul> <p>Other implementations:</p> <ul> <li>Page 972, <strong>Time Sheet Chart</strong></li> <li>Page 869, <strong>Cash Flow Chart</strong></li> <li>Page 760, <strong>Trailing Sales Orders Chart</strong></li> </ul> <h2 id="ideas-for-improvement">Ideas for improvement</h2> <p>We should consider making a generic table for the last chart that the user has used.</p> <p>We should investigate if we could make generic code for selecting periods and other common functionality by using RecordRefs.</p> <p>Add-In improvements &ndash; Different ways to visualize the data and to pick colors for categories.</p> <p>As a nice-to-have feature, we could implement functionality to cycle through the charts with a timer.</p>Docs: Cross Session Eventshttps://alguidelines.dev/docs/navpatterns/patterns/cross-session-events/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/cross-session-events/ <p><em>By Nikolai L&rsquo;Estrange, from TVision Technology Ltd. in the UK</em></p> <h2 id="abstract">Abstract</h2> <p>Track things that happen in other NAV Sessions.</p> <p><a href="PubSub.png"><img src="PubSub.png" alt=" "></a></p> <h2 id="problem">Problem</h2> <p>In Microsoft Dynamics NAV you can fire a function whenever something changes within your session (and from NAV 2016 this is even easier with the new Event model), however there is not an easy way to know what is happening in other sessions. Sometimes you would like to know what has happened since your last read, without reading everything again, e.g. when you need to pass a large dataset to a Control Add-in.</p> <p>A common way of handling this with Ledger Tables is to make note of the last record you read, and continuously poll to see if there are any new records. However this is restricted to strictly sequentially entered tables.</p> <h2 id="solution">Solution</h2> <p>There is a common pattern in many other languages called <a href="https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern">Publish-Subscribe</a> (or PubSub) that solves the same issue. We can implement the same pattern in NAV using a Table as a message queue platform and polling this table. We have named this pattern &ldquo;Cross Session Events&rdquo; in order to avoid confusion with the standard NAV Events which use the terms Publisher and Subscriber, and to try and describe more accurately when you would need this pattern.</p> <p>The pattern has four components:</p> <ul> <li><strong>Publisher(s)</strong>: These push messages to the Message Broker.</li> <li><strong>Subscriber Records</strong>: Identifies the Subscriber and store filters to say what messages the Subscriber and interested in receiving.</li> <li><strong>Message Broker</strong>: This distributes all messages sent in to all Subscribers that have expressed an interest (i.e. the message is within their filters).</li> <li><strong>Message Queue</strong>: To hold the messages for each Subscriber. Generally once these messages are read, they are deleted.</li> </ul> <h2 id="example">Example</h2> <p>An example of this would be when we have multiple users looking at the same set of data and we want their screens to update in &ldquo;real time&rdquo; whenever one of them makes a change, without doing a full refresh. We will use the <a href="https://alguidelines.dev/navpatterns/1-patterns/observer/">Observer pattern</a> to capture the change (act as the Publisher) and then create a Table to hold Subscribers and Filters (Change Observer), a Table to be the Message Queue (Change Notification), and a Codeunit to be the Message Broker and help with the polling (ObserverMgt).</p> <p>Below are the table definitions:</p> <table> <thead> <tr> <th><strong>Change Observer:</strong></th> <th></th> <th></th> </tr> </thead> <tbody> <tr> <td>&ldquo;Table ID&rdquo;</td> <td>Integer</td> <td>&ldquo;Observable Table&rdquo;</td> </tr> <tr> <td>&ldquo;Server ID&rdquo;</td> <td>Integer</td> <td></td> </tr> <tr> <td>&ldquo;Session ID&rdquo;</td> <td>Integer</td> <td></td> </tr> </tbody> </table> <table> <thead> <tr> <th><strong>Change Notification:</strong></th> <th></th> <th></th> </tr> </thead> <tbody> <tr> <td>&ldquo;Table ID&rdquo;</td> <td>Integer</td> <td>&ldquo;Observable Table&rdquo;</td> </tr> <tr> <td>&ldquo;Server ID&rdquo;</td> <td>Integer</td> <td></td> </tr> <tr> <td>&ldquo;Session ID&rdquo;</td> <td>Integer</td> <td></td> </tr> <tr> <td>&ldquo;Entry No.&rdquo;</td> <td>Integer</td> <td>AutoIncrement</td> </tr> <tr> <td>&ldquo;Type of Change&rdquo;</td> <td>Option</td> <td>Insert,Modify,Delete,Rename</td> </tr> <tr> <td>&ldquo;Record ID&rdquo;</td> <td>RecordID</td> <td></td> </tr> <tr> <td>&hellip; (other fields to indicate what has changed)</td> <td></td> <td></td> </tr> </tbody> </table> <p>The Change Observer table identifies the Subscriber using Server ID and Session ID, and then in this example there is only one filter, which is the Table ID we want to listen to any changes. In this case all three fields are in the Primary Key.</p> <p>The Change Notification table then has the same three fields plus an Entry No. as its Primary Key, and in this example borrows heavily from the Change Log code to fill in the rest of the message.</p> <p><em><strong>Note:</strong></em> Other examples of the pattern could have very different fields to identify the Subscriber, Filters and then whatever fields needed for content of the Message.</p> <p>Our Message Broker Codeunit will also serve as a central place to create Subscribers (Listen and StopListening functions) and a place to Poll for Messages. Note that the Poll function deletes the Messages as it reads them.</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="display:flex;"><span>Listen<span style="color:#ce5c00;font-weight:bold">(</span>TableID<span style="color:#f8f8f8;text-decoration:underline"> </span><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></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">WITH</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Observer<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DO</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Table ID&#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>TableID<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Server ID&#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>SERVICEINSTANCEID<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Session ID&#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>SESSIONID<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>INSERT<span style="color:#ce5c00;font-weight:bold">(</span>TRUE<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>COMMIT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>StopListening<span style="color:#ce5c00;font-weight:bold">(</span>TableID<span style="color:#f8f8f8;text-decoration:underline"> </span><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></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">WITH</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Observer<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DO</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RESET<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Server ID&#34;<span style="color:#000;font-weight:bold">,</span>SERVICEINSTANCEID<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Session ID&#34;<span style="color:#000;font-weight:bold">,</span>SESSIONID<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Table ID&#34;<span style="color:#000;font-weight:bold">,</span>TableID<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DELETEALL<span style="color:#ce5c00;font-weight:bold">(</span>TRUE<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>COMMIT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>NotifyAll<span style="color:#ce5c00;font-weight:bold">(</span>ChangeNotification<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Change Notification&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">WITH</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Observer<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DO</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RESET<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Table ID&#34;<span style="color:#000;font-weight:bold">,</span>ChangeNotification<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Table ID&#34;<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></span><span style="display:flex;"><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>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Notify<span style="color:#ce5c00;font-weight:bold">(</span>Observer<span style="color:#000;font-weight:bold">,</span>ChangeNotification<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>Notify<span style="color:#ce5c00;font-weight:bold">(</span>Observer<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Change Observer&#34;<span style="color:#000;font-weight:bold">;</span>ChangeNotification<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Change Notification&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">WITH</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ChangeNotification<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DO</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Server ID&#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>Observer<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Server ID&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Session ID&#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>Observer<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Session ID&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Entry 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><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>INSERT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>Poll<span style="color:#ce5c00;font-weight:bold">(</span>TableID<span style="color:#f8f8f8;text-decoration:underline"> </span><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:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempChangeNotification<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TEMPORARY</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;Change Notification&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">WITH</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ChangeNotification<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DO</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempChangeNotification<span style="color:#ce5c00;font-weight:bold">.</span>RESET<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempChangeNotification<span style="color:#ce5c00;font-weight:bold">.</span>DELETEALL<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RESET<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Table ID&#34;<span style="color:#000;font-weight:bold">,</span>TableID<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Server ID&#34;<span style="color:#000;font-weight:bold">,</span>SERVICEINSTANCEID<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Session ID&#34;<span style="color:#000;font-weight:bold">,</span>SESSIONID<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempChangeNotification<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ChangeNotification<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempChangeNotification<span style="color:#ce5c00;font-weight:bold">.</span>INSERT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MARK<span style="color:#ce5c00;font-weight:bold">(</span>TRUE<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MARKEDONLY<span style="color:#ce5c00;font-weight:bold">(</span>TRUE<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DELETEALL<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div><p>The final part of this example is an object that calls the functions above. In this example we will use a Page with a PingPong Timer Control to do the polling in (almost) real time. These are the functions on the 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="display:flex;"><span>OnQueryClosePage<span style="color:#ce5c00;font-weight:bold">(</span>CloseAction<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Action</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">None</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>ObserverMgt<span style="color:#ce5c00;font-weight:bold">.</span>StopListening<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>&#34;NAV Whiteboard Booking&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>Timer<span style="color:#000;font-weight:bold">::</span>AddInReady<span style="color:#ce5c00;font-weight:bold">() </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ObserverMgt<span style="color:#ce5c00;font-weight:bold">.</span>Listen<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>&#34;NAV Whiteboard Booking&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>CurrPage<span style="color:#ce5c00;font-weight:bold">.</span>Timer<span style="color:#ce5c00;font-weight:bold">.</span>Ping<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">1000</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>Timer<span style="color:#000;font-weight:bold">::</span>Pong<span style="color:#ce5c00;font-weight:bold">() </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>CallUpdate<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>CurrPage<span style="color:#ce5c00;font-weight:bold">.</span>Timer<span style="color:#ce5c00;font-weight:bold">.</span>Ping<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">1000</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>CallUpdate<span style="color:#ce5c00;font-weight:bold">() </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>ObserverMgt<span style="color:#ce5c00;font-weight:bold">.</span>Poll<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>&#34;NAV Whiteboard Booking&#34;<span style="color:#000;font-weight:bold">,</span>TempChangeNotification<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">WITH</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempChangeNotification<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DO</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></span><span style="display:flex;"><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>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>&#34;Type of Change&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span>&#34;Type of Change&#34;<span style="color:#000;font-weight:bold">::</span>Delete<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#204a87;font-weight:bold">END</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</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>RecRef<span style="color:#ce5c00;font-weight:bold">.</span>GET<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Record ID&#34;<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:#204a87;font-weight:bold">BEGIN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div><h2 id="consequences">Consequences</h2> <p>The PingPong control is only available on the Windows Client, so if you want to use another client you will need to use another solution to Poll for Messages. Therefore this pattern is not always going to be &ldquo;real time&rdquo;.</p> <h2 id="related-topics">Related Topics</h2> <p>This pattern was originally described in the following blog:</p> <p><a href="https://geeknikolai.wordpress.com/2015/10/30/pubsub-pattern-in-dynamics-nav-2016/">https://geeknikolai.wordpress.com/2015/10/30/pubsub-pattern-in-dynamics-nav-2016/</a></p> <p>Below is the Wikipedia link to the PubSub pattern</p> <p><a href="https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern">https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern</a></p>Docs: Cue Tablehttps://alguidelines.dev/docs/navpatterns/patterns/singleton/singleton-table/cue-table/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/singleton/singleton-table/cue-table/ <p><em>By Bogdana Botez at Microsoft Development Center Copenhagen</em></p> <p><a href="Cue-Table.png"><img src="Cue-Table.png" alt=" "></a></p> <p>Cues are the second usual application of the <a href="https://alguidelines.dev/navpatterns/1-patterns/singleton/singleton-table/"><strong>Singleton Table</strong></a> pattern in Dynamics NAV, after <a href="https://alguidelines.dev/navpatterns/1-patterns/singleton/singleton-table/setup-table/"><strong>Setup Tables</strong></a>.</p> <p><strong>Context</strong>: The user gets overview information about the business on the Dynamics NAV Role Center page.</p> <p>Figure 1 - Cue information in Dynamics NAV shows cue information seen by the user on the <strong>Sales Order Processor</strong> role center.</p> <p><a href="Cue-Table-Figure-1.JPG"><img src="Cue-Table-Figure-1.JPG" alt=" "></a></p> <p>The overview information consists of summed-up numbers, calculated from business data, like for example how many sales orders are still open, how many shipments are ready to go, or partially shipped, how many documents are waiting for approval etc.</p> <p><strong>Problem</strong>: NAV stores data in tables. By definition, a table is a repetitive structure containing multiple lines, each line having a different piece of the information. But sometimes this repetitive information needs to be summed-up or otherwise synthetized, and presented as an overview.</p> <p><strong>Solution:</strong> Store overview information in a singleton table.</p> <p>There are two ways of calculating overview information in NAV.</p> <ol> <li> <p>By using a FlowField. This applies for simpler calculations, like filtered or unfiltered counts, sums etc.</p> </li> <li> <p>By writing C/AL code to perform custom calculations. Use this when:</p> <ul> <li>The way to calculate the overview is too complex for flow fields, or</li> <li>The data needs to be pulled from an external system (like Dynamics CRM, QuickBooks or any external integration).</li> </ul> </li> </ol> <p>The implementation of Cues is already described in detail on MSDN, in <a href="https://msdn.microsoft.com/en-us/library/dn789553(v=nav.90).aspx">Creating and Customizing Cues</a> and in <a href="https://msdn.microsoft.com/en-us/library/ff477101(v=nav.90).aspx">Walkthrough: Creating a Cue Based on a FlowField</a>.</p> <p><strong>NAV Usages</strong></p> <p><em>Table 1 - Cue tables in Dynamics NAV</em> shows some examples of singleton tables used for creating Cues.</p> <table> <thead> <tr> <th>Table ID</th> <th>Table Name</th> </tr> </thead> <tbody> <tr> <td>1313</td> <td>Activities Cue</td> </tr> <tr> <td>5370</td> <td>CRM Synch. Job Status Cue</td> </tr> <tr> <td>9042</td> <td>Team Member Cue</td> </tr> <tr> <td>9050</td> <td>Warehouse Basic Cue</td> </tr> <tr> <td>9051</td> <td>Warehouse WMS Cue</td> </tr> <tr> <td>9052</td> <td>Service Cue</td> </tr> <tr> <td>9053</td> <td>Sales Cue</td> </tr> <tr> <td>9054</td> <td>Finance Cue</td> </tr> <tr> <td>9055</td> <td>Purchase Cue</td> </tr> <tr> <td>9056</td> <td>Manufacturing Cue</td> </tr> <tr> <td>9057</td> <td>Job Cue</td> </tr> <tr> <td>9058</td> <td>Warehouse Worker WMS Cue</td> </tr> <tr> <td>9059</td> <td>Administration Cue</td> </tr> <tr> <td>9060</td> <td>SB Owner Cue</td> </tr> <tr> <td>9061</td> <td>RapidStart Services Cue</td> </tr> <tr> <td>9063</td> <td>Relationship Mgmt. Cue</td> </tr> <tr> <td>9069</td> <td>O365 Sales Cue</td> </tr> <tr> <td>9070</td> <td>Accounting Services Cue</td> </tr> </tbody> </table> <p>Table 1 - Cue tables in Dynamics NAV</p>Docs: Currently Active Recordhttps://alguidelines.dev/docs/navpatterns/patterns/currently-active-record/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/currently-active-record/ <p><em>Authors: Henrik Langbak and Kim Ginnerup, Bording Data</em></p> <h2 id="abstract">Abstract</h2> <p>Date controlled data is expensive to find in the database. This pattern describes how using a view with a sub-select and a linked table object will minimize the returned dataset.<br> 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&rsquo;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> <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> </li> <li> <p>The NAV Service Tier receives and throws away data.</p> </li> </ul> <h2 id="ending-date-problem">Ending Date Problem</h2> <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> Ending Date creates a dependency between two records. Changing a Starting Date, requires you to update the previous record. Changing the Ending Date requires you to update the next record.<br> If you add a record in between you will have to update both the before and the after record.</p> <p>The pattern we describe here will work whether there is an Ending Date or Not.</p> <p>The pattern is also relevant for other types than date. The pattern is usable whenever you have dependencies between rows in a table.</p> <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 &ldquo;Sales Price Calc. Mgt.&rdquo;. 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><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> <div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">CREATE</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">VIEW</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">[</span><span style="color:#000">dbo</span><span style="color:#000;font-weight:bold">].[</span><span style="color:#000">CRONUS$PriceView</span><span style="color:#000;font-weight:bold">]</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">AS</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">SELECT</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">[</span><span style="color:#000">Code</span><span style="color:#000;font-weight:bold">],</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">[</span><span style="color:#000">Starting</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87">Date</span><span style="color:#000;font-weight:bold">],</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">[</span><span style="color:#000">Price</span><span style="color:#000;font-weight:bold">]</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">FROM</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">dbo</span><span style="color:#000;font-weight:bold">.[</span><span style="color:#000">CRONUS$Price</span><span style="color:#000;font-weight:bold">]</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">AS</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">A</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">WHERE</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">[</span><span style="color:#000">Starting</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87">Date</span><span style="color:#000;font-weight:bold">]</span><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">SELECT</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">MAX</span><span style="color:#000;font-weight:bold">([</span><span style="color:#000">Starting</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87">Date</span><span style="color:#000;font-weight:bold">])</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">FROM</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">dbo</span><span style="color:#000;font-weight:bold">.[</span><span style="color:#000">CRONUS$Price</span><span style="color:#000;font-weight:bold">]</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">AS</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">B</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">WHERE</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">B</span><span style="color:#000;font-weight:bold">.[</span><span style="color:#000">Code</span><span style="color:#000;font-weight:bold">]</span><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:#000">A</span><span style="color:#000;font-weight:bold">.[</span><span style="color:#000">Code</span><span style="color:#000;font-weight:bold">]</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">AND</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000">B</span><span style="color:#000;font-weight:bold">.[</span><span style="color:#000">Starting</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87">Date</span><span style="color:#000;font-weight:bold">]</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">&lt;=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">GETDATE</span><span style="color:#000;font-weight:bold">())</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></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> <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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>PriceView<span style="color:#ce5c00;font-weight:bold">.</span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// You have them </span></span></span></code></pre></div><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&rsquo;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> <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> <ul> <li>If you add columns, you need to add them to the view first and then add them to the Table Object.</li> <li>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.</li> </ul> <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> <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="display:flex;"><span>Price<span style="color:#ce5c00;font-weight:bold">.</span>SETCURRENTKEY<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Code</span><span style="color:#000;font-weight:bold">,</span>&#34;Starting Date&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>Price<span style="color:#ce5c00;font-weight:bold">.</span>SETFILTER<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Starting Date&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;..%1&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TODAY<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>Price<span style="color:#ce5c00;font-weight:bold">.</span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Price<span style="color:#ce5c00;font-weight:bold">.</span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Code</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Price<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">Code</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Price<span style="color:#ce5c00;font-weight:bold">.</span>FINDLAST<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Price<span style="color:#ce5c00;font-weight:bold">.</span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Code</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>PriceTemp<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Price<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>PriceTemp<span style="color:#ce5c00;font-weight:bold">.</span>INSERT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Price<span style="color:#ce5c00;font-weight:bold">.</span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#8f5902;font-style:italic">// PriceTemp will contain the Prices </span></span></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> <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.</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> The NAV example will require SQL Server to read all data older than or equal to TODAY, but only return one row per Code. Over time, as old data piles up in the system, the NAV code will perform slower because the SQL statements will be slower.<br> The Pattern makes a scalable solution with a predictable performance. The performance will not deteriorate at the same rate as the NAV code example.</p> <h2 id="nav-usages">NAV Usages</h2> <p>The pattern does not exist in NAV (yet J). We have used it several times in our code for an Add-On.</p> <h2 id="ideas-for-improvement">Ideas for improvement</h2> <p>Query Object should be able to handle sub-selects and Unions. A simple solution could be to allow the NAV developer to specify the actual Select statement inside the query Object in clear text. Opening up for writing your own queries and map the projection to the Query-defined fields will make the query Object very versatile and remove the pressure from Microsoft trying to create all the different permutations that a select statement can have. Microsoft and others have all tried to create wizards that can create SQL select statement. They all end up having a clear text option.</p> <p>An alternative would be better support for linked table objects, specifically views. The current implementation is very fragile.</p> <p>The pattern only supports fetching data for a given date (normally today). This is because you cannot control the where-clause of the sub-select.</p> <h2 id="related-topics">Related Topics</h2> <p>The idea of having a linked table object pointing to a view could be a pattern of its own.</p>Docs: Cyclomatic Complexityhttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/cyclomatic-complexity/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/cyclomatic-complexity/ <p>Do not write functions that have high cyclomatic complexity. This makes the code hard to maintain.</p> <p>Bad code</p> <pre><code>Any procedure / trigger that has a cyclomatic complexity &gt; 25, using the CC3 version mentioned in [this article][anchor0]. </code></pre> <p>Good code</p> <pre><code>Any procedure / trigger that has a cyclomatic complexity &lt;= 25, using the CC3 version. The CC3 version is computed by summing the following in a code block: - each IF statement as 1\. - each entire CASE as 1\. </code></pre>Docs: Data Driven Blocked Entityhttps://alguidelines.dev/docs/navpatterns/patterns/blocked-entity/data-driven-blocked-entity/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/blocked-entity/data-driven-blocked-entity/ <p><em>Written by Bogdan Andrei Sturzoiu, at Microsoft Development Center Copenhagen</em></p> <h2 id="abstract">Abstract</h2> <p>This pattern implements a generic mechanism for dynamically restricting and allowing usage of a record by the business process administrator.</p> <h2 id="problem">Problem</h2> <p>A NAV record can be used in a number of functionalities across the app. There are situations, however, when the administrator wants to restrict the consumption of such a record, as well as lift the restriction when it is no longer relevant.</p> <p>For example, a new customer record should not be used for posting documents until it is approved by the relevant approver.</p> <p>We could solve this by using the <a href="https://alguidelines.dev/navpatterns/1-patterns/blocked-entity/">Blocked Entity pattern</a>, but it requires database schema changes, which have an upgrade impact.</p> <p>The blocked entity pattern involves:</p> <ol> <li>Adding a &ldquo;blocked&rdquo; status field on the record (either a Boolean or in the more advanced cases, an option field refining the usage).</li> <li>Adding specific code for the record in every place where the restriction needs to be enforced.</li> </ol> <p>In contrast, the Data-driven Blocked Entity pattern involves adding a new record (data change) to mark the restriction, instead of adding a new field (metadata change).</p> <h2 id="solution">Solution</h2> <p>This pattern describes a generic mechanism of adding and lifting restrictions for any type of record.</p> <p>The restriction mechanism has the following elements:</p> <ol> <li>Adding a restriction record for a specific reason (e.g. the record requires approval), which will act as a surrogate key (unique identifier) for the restricted record. This can be implemented through a workflow response, or directly, by calling the Restriction Management codeunit function.</li> <li>Lifting the restriction when it is no longer necessary. Again, this can be done using a workflow response or directly by calling the dedicated function.</li> <li>Consuming the restriction in the places of interest for a specific purpose. This is an application feature that requires a call to the Restriction Management codeunit to check for restrictions.</li> </ol> <p>Currently, the restrictions are record-based and type-less. They act as simple tokens, and they have:</p> <ul> <li>A reason (e.g. the record requires approval)</li> <li>A purpose (e.g. the record cannot be posted).</li> </ul> <p>You must make sure to differentiate between the reason and the purpose. That is because the restriction can only be added once per record, but consumed in multiple places.</p> <h2 id="example">Example</h2> <p>For example, we want to restrict posting Gen. Journal Lines if a customer has not been added in Account No. field.</p> <p>For this, the following components are needed:</p> <ol> <li>When a Gen. Journal Line is inserted, call RestrictRecordUsage in COD1550, either directly in the trigger or using an event subscriber.</li> <li>When you validate a Customer No. as Account no. and Customer as Account Type, lift the restrictions by calling AllowRecordUsage in COD1550.</li> <li>The consumption of the restriction at posting is already implemented as an event in TAB81, OnCheckGenJournalLinePostRestrictions. No further action necessary.</li> </ol> <h2 id="nav-usage">NAV Usage</h2> <p>All the approval workflows include a response that restricts usage of a record, and then, at the end of an approval loop, a response that allows the usage again by lifting the restriction. See responses &ldquo;Add record restriction&rdquo; and &ldquo;Remove record restriction&rdquo; implemented in COD1521.<a href="https://microsoft.sharepoint.com/teams/DynamicsNAV/Wiki/Nav%20Wiki%20Documents/NAV%20App%20Patterns/NAV%20App%20Patterns%20for%20Review/Data-Driven%20Blocked%20Entity.docx#_msocom_2"><br> </a></p> <p>The code behind the &ldquo;Add record restriction&rdquo; workflow response:</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="display:flex;"><span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span>GETTABLE<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Variant</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>Workflow<span style="color:#ce5c00;font-weight:bold">.</span>GET<span style="color:#ce5c00;font-weight:bold">(</span>WorkflowStepInstance<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Workflow Code&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>RecordRestrictionMgt<span style="color:#ce5c00;font-weight:bold">.</span>RestrictRecordUsage<span style="color:#ce5c00;font-weight:bold">(</span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">RECORDID</span><span style="color:#000;font-weight:bold">,</span>STRSUBSTNO<span style="color:#ce5c00;font-weight:bold">(</span>RestrictUsageDetailsTxt<span style="color:#000;font-weight:bold">,</span>Workflow<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">Code</span><span style="color:#000;font-weight:bold">,</span>Workflow<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></span></code></pre></div><p>The code behind the &ldquo;Remove record restriction&rdquo; response:</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="display:flex;"><span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span>GETTABLE<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">Variant</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">CASE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span>NUMBER<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">OF</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>&#34;Approval Entry&#34;<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecordRestrictionMgt<span style="color:#ce5c00;font-weight:bold">.</span>AllowRecordUsage<span style="color:#ce5c00;font-weight:bold">(</span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">RECORDID</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></span><span style="display:flex;"><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>ApprovalEntry<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span>GET<span style="color:#ce5c00;font-weight:bold">(</span>ApprovalEntry<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Record ID to Approve&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>AllowRecordUsage<span style="color:#ce5c00;font-weight:bold">(</span>RecRef<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></span><span style="display:flex;"><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></span><span style="display:flex;"><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>&#34;Gen. Journal Batch&#34;<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><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>GenJournalBatch<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecordRestrictionMgt<span style="color:#ce5c00;font-weight:bold">.</span>AllowGenJournalBatchUsage<span style="color:#ce5c00;font-weight:bold">(</span>GenJournalBatch<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">END</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RecordRestrictionMgt<span style="color:#ce5c00;font-weight:bold">.</span>AllowRecordUsage<span style="color:#ce5c00;font-weight:bold">(</span>RecRef<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">RECORDID</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></span><span style="display:flex;"><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></span></code></pre></div><p>Notice how lifting a restriction for a Gen. Journal Batch involves lifting all the restrictions for the individual journal lines in the batch (hence the special branching of the code).</p> <h2 id="consequences">Consequences</h2> <p>Currently, there can only be one restriction per record. There are no restriction types.</p> <p>In the future, a type field should be added to the restriction table, to allow adding restrictions for different purposes, and to refine their consumption. For example, a posting restriction might only be enforced for restrictions originating from approvals.</p> <h2 id="nav-versions">NAV Versions</h2> <p>This pattern has been introduced in Dynamics NAV 2016.</p>Docs: Data Migration Façadehttps://alguidelines.dev/docs/navpatterns/patterns/data-migration-facade/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/data-migration-facade/ <p><em>By David Bastide and Soumya Dutta at Microsoft Development Center Copenhagen</em></p> <p><a href="8308.logo.png"><img src="8308.logo.png" alt=" "></a></p> <h2 id="context">Context:</h2> <p>This pattern is describing how you can migrate data using the Data Migration Façade.</p> <h2 id="problem">Problem:</h2> <p>Writing migration code from an external source, such as a product from a competitor, can be time consuming, as you need to tackle the problems of what to migrate, in which order, exception handling&hellip; and can result in code that is fragile due to deep dependencies on the NAV data model (high coupling). Any change to the NAV data model can easily break this code.</p> <h2 id="solution">Solution:</h2> <p>The idea of the Data Migration Façade is to provide an API that creates and updates master data and related entities (including transactions) without referencing NAV tables.</p> <p>Additionally, the framework around the Data Migration Façade provides tools for error handling, and a way to integrate the migration in the Data Migration Overview page (page 1799).</p> <p>The façade framework has the following components:</p> <ul> <li> <p>Two management codeunits:</p> <ul> <li><strong>Data Migration Façade</strong> (codeunit 6100): Integrates the extension to the Data Migration Wizard. Starts a migration, or restarts a migration that failed for some records.</li> <li><strong>Data Migration Status Facade</strong> (codeunit 6101): Initializes and updates the status of the migration. The status displays in the <strong>Data Migration Overview</strong> page (page 1799).</li> </ul> </li> <li> <p>Several master data migration façade codeunits that create and update entities. Each codeunit also contains events that help ensure that data is created in the correct order:</p> <ul> <li><strong>GL Acc. Data Migration Façade</strong> (codeunit 6110)</li> <li><strong>Vendor Data Migration Façade</strong> (codeunit 6111)</li> <li><strong>Customer Data Migration Façade</strong> (codeunit 6112)</li> <li><strong>Item Data Migration Façade</strong> (codeunit 6113)</li> <li>If you want to migrate other entities, it is possible to define your own codeunit that will contain your custom code (see &lsquo;Usage&rsquo; below).</li> </ul> </li> <li> <p>A page where you can view the status and progress of the migration. It shows one line for each master data entity (item, customer, vendor, general ledger account) that was chosen for migration. You can also stop a migration by choosing the <strong>Stop Migration</strong> action.</p> <ul> <li><strong>Data Migration Overview</strong> (page 1799)</li> </ul> </li> </ul> <h2 id="usage">Usage:</h2> <p>There are the following use cases:</p> <ul> <li> <p>Migration with staging tables, where data from another product is exported to a file or set of files, and the exported data is then imported to buffer tables, before running the migration logic. In this case, the migration is implemented in your extension codeunits, and it is called through events, one record at a time.</p> </li> <li> <p>Migration without staging tables, for example, when you migrate data by importing it from an external tool such as external APIs and webservices. In this case, the migration is also implemented in your extension codeunits but it will be called through the OnRun procedure. You will be responsible for looping on the records to migrate, and you must migrate all records in this unique OnRun call for a given entity.</p> </li> </ul> <p>To initialize and start the data migration, you must call the following procedures:</p> <ul> <li><strong>&ldquo;Data Migration Status Façade&rdquo;.InitStatusLine(&lsquo;My Migration Type&rsquo;,Database::Item,42000,0,Codeunit::&ldquo;My extension Item migration codeunit&rdquo;)</strong><br> This deletes existing status lines for migrating Items for &lsquo;My Migration Type&rsquo;, and initializes a new status line with 0 records migrated out of 42000.</li> </ul> <p><strong>&ldquo;Data Migration Façade&rdquo;.StartMigration(&lsquo;My Migration Type&rsquo;,false)</strong><br> This starts the migration. False means this is not a retry. A re-try is when you migrate one or more records from the <strong>Show Errors</strong> page, which is described later in this document. Retry = true is only used by the <strong>Show Errors</strong> page and should not be used from extensions.</p> <h3 id="usage-without-staging-tables">Usage without staging tables:</h3> <p>The overall workflow is:</p> <ol> <li>Integrate your extension in the <strong>Data Migration Wizard</strong> by subscribing to the events exposed by the <strong>Data Migration Façade</strong>.</li> <li>From there, initialize the status of the migration so it can be displayed in the Data Migration Overview. When initializing the status lines, you provide the codeunit ID that will be called for each entity: <strong>&ldquo;Data Migration Status Façade&rdquo;.InitStatusLine(&lsquo;My Migration Type&rsquo;,Database::Item,42000,0,Codeunit::&ldquo;My extension Item migration codeunit&rdquo;)</strong>.</li> <li>Launch the migration: <strong>&ldquo;Data Migration Façade&rdquo;.StartMigration(&lsquo;My Migration Type&rsquo;,false).</strong></li> <li>Your migration codeunits are called one at a time (<strong>OnRun</strong>) in the following order:</li> <li>G/L accounts (first, because customer/vendor posting groups refer to G/L accounts)</li> <li>Customers</li> <li>Vendors</li> <li>Items (because discounts may refer to customer groups)</li> <li>Others</li> <li>Loop on all of the records to migrate. You can update the increment of the amount of records migrated: <strong>&ldquo;Data Migration Status Facade&rdquo;.IncrementStatusLine(&lsquo;My Migration Type&rsquo;,Database::Item,42).</strong></li> </ol> <p><a href="NoStagingTableNew2.png"><img src="NoStagingTableNew2.png" alt=" "></a></p> <p><em>Figure 1: sequence diagram of the data migration without staging tables</em></p> <p>The following example shows how to migrate items without staging tables:</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">trigger</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OnRun<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></span><span style="display:flex;"><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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemDataMigrationFacade<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 Data Migration Facade&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemNumber<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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemJson<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// loop on items retrieved through a web service for example </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">for</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemNumber<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:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">to</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ExternalWebService<span style="color:#ce5c00;font-weight:bold">.</span>GetItemCount<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">do</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ExternalWebService<span style="color:#ce5c00;font-weight:bold">.</span>GetItem<span style="color:#ce5c00;font-weight:bold">(</span>ItemNumber<span style="color:#000;font-weight:bold">,</span>ItemJson<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// create item using the facade </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></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>ItemDataMigrationFacade<span style="color:#ce5c00;font-weight:bold">.</span>CreateItemIfNeeded<span style="color:#ce5c00;font-weight:bold">(</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>ItemNumber<span style="color:#000;font-weight:bold">,</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>ItemName1<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>ItemName2<span style="color:#000;font-weight:bold">,</span>ConvertItemType<span style="color:#ce5c00;font-weight:bold">(</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>ItemType<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></span><span style="display:flex;"><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:#8f5902;font-style:italic">// item already exists </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// set some fields using the facade </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemDataMigrationFacade<span style="color:#ce5c00;font-weight:bold">.</span>SetVendorItemNo<span style="color:#ce5c00;font-weight:bold">(</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>VendItemNumber<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemDataMigrationFacade<span style="color:#ce5c00;font-weight:bold">.</span>SetUnitVolume<span style="color:#ce5c00;font-weight:bold">(</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>Volume<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemDataMigrationFacade<span style="color:#ce5c00;font-weight:bold">.</span>SetAlternativeItemNo<span style="color:#ce5c00;font-weight:bold">(</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>AltItemNumber<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></span><span style="display:flex;"><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>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>PrimaryVendor<span style="color:#f8f8f8;text-decoration:underline"> </span>&lt;&gt;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemDataMigrationFacade<span style="color:#ce5c00;font-weight:bold">.</span>SetVendorNo<span style="color:#ce5c00;font-weight:bold">(</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>PrimaryVendor<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// migrate dependencies </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>MigrateItemUnitOfMeasure<span style="color:#ce5c00;font-weight:bold">(</span>ItemDataMigrationFacade<span style="color:#000;font-weight:bold">,</span>ItemJson<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// modify the item (+run trigger) to save the changes made by setters </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemDataMigrationFacade<span style="color:#ce5c00;font-weight:bold">.</span>ModifyItem<span style="color:#ce5c00;font-weight:bold">(</span>true<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// update the status in the migration dashboard </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>DataMigrationStatusFacade<span style="color:#ce5c00;font-weight:bold">.</span>IncrementMigratedRecordCount<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#39;My Migration Type&#39;</span><span style="color:#000;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:#0000cf;font-weight:bold">1</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></span><span style="display:flex;"><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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>MigrateItemUnitOfMeasure<span style="color:#ce5c00;font-weight:bold">(</span>ItemDataMigrationFacade<span style="color:#f8f8f8;text-decoration:underline"> </span><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 Data Migration Facade&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemJson<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</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></span><span style="display:flex;"><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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyUnitCodeStagingTable<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;My Unit Code Staging Table&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DataMigrationStatusFacade<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;Data Migration Status Facade&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DescriptionToSet<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</span>[<span style="color:#0000cf;font-weight:bold">10</span>]<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>UnitCodeJson<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><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>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>UnitCode<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// log an error using the Data migration façade </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>DataMigrationStatusFacade<span style="color:#ce5c00;font-weight:bold">.</span>RegisterErrorNoStagingTablesCase<span style="color:#ce5c00;font-weight:bold">( </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#4e9a06">&#39;My Migration Type&#39;</span><span style="color:#000;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:#4e9a06">&#39;Unit of measure is empty.&#39;</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>ExternalWebService<span style="color:#ce5c00;font-weight:bold">.</span>GetUnitCode<span style="color:#ce5c00;font-weight:bold">(</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>UnitCode<span style="color:#000;font-weight:bold">,</span>UnitCodeJson<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DescriptionToSet<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>UnitCodeJson<span style="color:#ce5c00;font-weight:bold">.</span>Description<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemDataMigrationFacade<span style="color:#ce5c00;font-weight:bold">.</span>CreateUnitOfMeasureIfNeeded<span style="color:#ce5c00;font-weight:bold">(</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>UnitCode<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>DescriptionToSet<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// set the unit of measure on the item </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>ItemDataMigrationFacade<span style="color:#ce5c00;font-weight:bold">.</span>SetBaseUnitOfMeasure<span style="color:#ce5c00;font-weight:bold">(</span>ItemJson<span style="color:#ce5c00;font-weight:bold">.</span>UnitCode<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></span><span style="display:flex;"><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></span></code></pre></div><p><em>Figure 2: Example of Item and Item Unit of Measure migration without staging tables</em></p> <h3 id="usage-with-staging-tables">Usage with staging tables:</h3> <p>The overall workflow is:</p> <ul> <li> <p>Integrate your extension in the Data Migration Wizard by subscribing to the events exposed by the <strong>Data Migration Façade</strong>.</p> </li> <li> <p>From there, initialize the status of the migration so it can be displayed in the <strong>Data Migration Overview: &ldquo;Data Migration Status Façade&rdquo;.InitStatusLine(&lsquo;My Migration Type&rsquo;,Database::Item,42000,Database::&ldquo;My extension Staging table for items&rdquo;,0)</strong>.</p> </li> <li> <p>You can either fill the staging tables from the wizard events, or in a subscriber to the event dedicated to filling staging tables (<strong>&lsquo;OnFillStagingTables&rsquo;</strong> in codeunit 6100): in this case, the import of data from the files to the staging tables will be done in the background.</p> </li> <li> <p>Launch the migration: <strong>&ldquo;Data Migration Façade&rdquo;.StartMigration(&lsquo;My Migration Type&rsquo;,false)</strong>.</p> </li> <li> <p>Subscribe to the events to migrate entities and their dependencies.</p> </li> <li> <p>From the event subscribers, call the façade procedures to create entities and set their field values:</p> <ul> <li><strong>&ldquo;Item Data Migration Façade&rdquo;.CreateItemIfNeeded(&lsquo;ITEM042&rsquo;,&lsquo;My Item Description&rsquo;;&lsquo;My Item Description 2&rsquo;;ItemTypeToSet::Inventory)</strong></li> <li><strong>&ldquo;Item Data Migration Façade&rdquo;.SetBaseUnitOfMeasure(&lsquo;BOX&rsquo;)</strong></li> <li><strong>&ldquo;Item Data Migration Façade&rdquo;.ModifyItem(true)</strong></li> </ul> </li> </ul> <p><a href="StagingTableNew2.png"><img src="StagingTableNew2.png" alt=" "></a></p> <p><em>Figure 3: Simplified sequence diagram of the data migration with staging tables</em></p> <p>Below is a simplified example showing how to create an item:</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="display:flex;"><span>[EventSubscriber<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">ObjectType</span><span style="color:#000;font-weight:bold">::</span><span style="color:#204a87;font-weight:bold">Codeunit</span><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:#000;font-weight:bold">::</span>&#34;Item Data Migration Facade&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;OnMigrateItem&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<span style="color:#ce5c00;font-weight:bold">)</span>]<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>OnMigrateItem<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>Sender<span style="color:#f8f8f8;text-decoration:underline"> </span><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 Data Migration Facade&#34;<span style="color:#000;font-weight:bold">;</span>RecordIdToMigrate<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">RecordId</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></span><span style="display:flex;"><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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyItemStagingTable<span style="color:#f8f8f8;text-decoration:underline"> </span><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;My Item Staging Table&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// handle the event if it targets this extension&#39;s staging table </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></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>RecordIdToMigrate<span style="color:#ce5c00;font-weight:bold">.</span>TableNo<span style="color:#f8f8f8;text-decoration:underline"> </span>&lt;&gt;<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>&#34;My Item Staging Table&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>Get<span style="color:#ce5c00;font-weight:bold">(</span>RecordIdToMigrate<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// create item using the facade </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></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>Sender<span style="color:#ce5c00;font-weight:bold">.</span>CreateItemIfNeeded<span style="color:#ce5c00;font-weight:bold">(</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>ItemNumber<span style="color:#000;font-weight:bold">,</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>ItemName1<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>ItemName2<span style="color:#000;font-weight:bold">,</span>ConvertItemType<span style="color:#ce5c00;font-weight:bold">(</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>ItemType<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></span><span style="display:flex;"><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:#8f5902;font-style:italic">// item already exists </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// set some fields using the facade </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>Sender<span style="color:#ce5c00;font-weight:bold">.</span>SetVendorItemNo<span style="color:#ce5c00;font-weight:bold">(</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>VendItemNumber<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Sender<span style="color:#ce5c00;font-weight:bold">.</span>SetUnitVolume<span style="color:#ce5c00;font-weight:bold">(</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>Volume<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Sender<span style="color:#ce5c00;font-weight:bold">.</span>SetAlternativeItemNo<span style="color:#ce5c00;font-weight:bold">(</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>AltItemNumber<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></span><span style="display:flex;"><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>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>PrimaryVendor<span style="color:#f8f8f8;text-decoration:underline"> </span>&lt;&gt;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Sender<span style="color:#ce5c00;font-weight:bold">.</span>SetVendorNo<span style="color:#ce5c00;font-weight:bold">(</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>PrimaryVendor<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// modify the item (+run trigger) to save the changes made by setters </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>Sender<span style="color:#ce5c00;font-weight:bold">.</span>ModifyItem<span style="color:#ce5c00;font-weight:bold">(</span>true<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></span><span style="display:flex;"><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></span></code></pre></div><p><em>Figure 4: Example of event subscriber for Item migration</em></p> <p>Below is another example showing how to use additional events to set fields that reference other tables, here the unit of measure:</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="display:flex;"><span>[EventSubscriber<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">ObjectType</span><span style="color:#000;font-weight:bold">::</span><span style="color:#204a87;font-weight:bold">Codeunit</span><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:#000;font-weight:bold">::</span>&#34;Item Data Migration Facade&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;OnMigrateItemUnitOfMeasure&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<span style="color:#ce5c00;font-weight:bold">)</span>]<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>OnMigrateItemUnitOfMeasure<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>Sender<span style="color:#f8f8f8;text-decoration:underline"> </span><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 Data Migration Facade&#34;<span style="color:#000;font-weight:bold">;</span>RecordIdToMigrate<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">RecordId</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></span><span style="display:flex;"><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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyItemStagingTable<span style="color:#f8f8f8;text-decoration:underline"> </span><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;My Item Staging Table&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyUnitCodeStagingTable<span style="color:#f8f8f8;text-decoration:underline"> </span><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;My Unit Code Staging Table&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DescriptionToSet<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Text</span>[<span style="color:#0000cf;font-weight:bold">10</span>]<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// handle the event if it targets this extension&#39;s staging table </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></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>RecordIdToMigrate<span style="color:#ce5c00;font-weight:bold">.</span>TableNo<span style="color:#f8f8f8;text-decoration:underline"> </span>&lt;&gt;<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>&#34;My Item Staging Table&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>Get<span style="color:#ce5c00;font-weight:bold">(</span>RecordIdToMigrate<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></span><span style="display:flex;"><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>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>UnitCode<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>error<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#39;Unit of measure is empty.&#39;</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyUnitCodeStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>SetRange<span style="color:#ce5c00;font-weight:bold">(</span>UnitCode<span style="color:#000;font-weight:bold">,</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>UnitCode<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></span><span style="display:flex;"><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>MyUnitCodeStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>FindFirst<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DescriptionToSet<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>MyUnitCodeStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>Description<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// create the unit of measure through the facade </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>Sender<span style="color:#ce5c00;font-weight:bold">.</span>CreateUnitOfMeasureIfNeeded<span style="color:#ce5c00;font-weight:bold">(</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>UnitCode<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>DescriptionToSet<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// set the unit of measure on the item </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>Sender<span style="color:#ce5c00;font-weight:bold">.</span>SetBaseUnitOfMeasure<span style="color:#ce5c00;font-weight:bold">(</span>MyItemStagingTable<span style="color:#ce5c00;font-weight:bold">.</span>UnitCode<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// modify the item to save the changes made by setter </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span>Sender<span style="color:#ce5c00;font-weight:bold">.</span>ModifyItem<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></span><span style="display:flex;"><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></span></code></pre></div><p><em>Figure 5: Example of event subscriber for Item Unit of Measure migration</em></p> <h3 id="combining-both-approaches">Combining both approaches:</h3> <p>If you want to migrate additional entities, the <strong>Data Migration</strong> framework lets you initialize the migration with entities other than master data. In this case, the <strong>Data Migration Overview</strong> page will show additional lines. Item, vendor, customer, an general ledger accounts are migrated with an event driven approach, and the additional entities are migrated by calling an extension codeunit <strong>OnRun</strong> method.</p> <h2 id="error-handling-with-staging-tables">Error handling with staging tables:</h2> <p>The migration starts by calling <strong>RUN</strong> on the façade codeunit. Errors thrown during the call are captured by <strong>GETLASTERRORTEXT</strong> and displayed when you choose the <strong>Show Errors</strong> action on the <strong>Data Migration Overview</strong> page.</p> <p><a href="errorhandling1.png"><img src="errorhandling1.png" alt=" "></a></p> <p><em>Figure 6: List of errors shown when clicking <strong>Show Errors</strong> on the <strong>Data Migration Overview</strong> page</em></p> <p>The <strong>Edit Record</strong> action opens a view of the staging table, where you can edit fields to fix errors. Figure 4 shows an example of a page for the vendor staging table in a migration from C5.</p> <p><a href="errorhandling2.png"><img src="errorhandling2.png" alt=" "></a></p> <p><em>Figure 7: Edit a staging table record</em></p> <p>The <strong>Staging Table ID</strong> determines the page to open, so it is important that the page ID is equal to the <strong>Staging Table ID</strong>, at least for the master data staging tables, for example, for <strong>G/L Accounts, Items, Customers</strong> and <strong>Vendor</strong>. You should ensure that pages to edit related entities are linked on this page by means of new actions. For example, Figure 4 uses the <strong>C5 Purchaser</strong> action.</p> <p>After you fix the staging table record, you can choose the <strong>Migrate</strong> action to mark the selected records as records to retry, and then run <strong>StartMigration</strong> with the <strong>Retry</strong> flag set to true. This is the only place where the retry flag should be set to true in the <strong>StartMigration</strong> procedure.</p> <p>Error handling without staging tables</p> <p>When migrating data without staging tables, errors can be registered manually by the extension using <strong>DataMigrationStatusFacade.RegisterErrorNoStagingTablesCase</strong>. Otherwise they can be registered automatically if the codeunits fail when called on their <strong>OnRun</strong> procedure.</p> <p>Errors will be displayed in the error list, but you cannot open and edit records because there is no staging table. The Edit action will not be available.</p> <h2 id="limitations">Limitations:</h2> <ul> <li> <p>Data migration will fail if there are customers, vendors, items in the database and if these entities are selected for migration. For example, if you choose to migrate items and your company already contains items, you will get an error. This should not be an issue if you migrate your data from another tool to NAV, in which case you will most likely start on a fresh empty company. However, if you just want to import additional items to a company with existing items, then it is not supported by the framework. however, you can still use the different functions provided by the different codeunits (such as <strong>Item Data Migration Facade</strong>) to create the entities without strong coupling on the NAV data model.</p> </li> <li> <p><strong>G/L entries</strong> are deleted automatically.</p> </li> <li> <p>There is no automated rollback in case of failure: data that is successfully migrated will be commited, and data that is not successfully migrated with be shown in the errors list. The retry feature (in case of staging tables) then makes it possible for you to retry individual entities or ignore them.</p> </li> </ul> <h2 id="usages-in-nav">Usages in NAV:</h2> <p>The Data Migration Façade is available starting from version 2018.</p> <p>The following Façade codeunits for data migration management are available:</p> <ul> <li> <p>COD6100 (<strong>Data Migration Facade</strong>)</p> </li> <li> <p>COD6101 (<strong>Data Migration Status Facade</strong>)</p> </li> </ul> <p>The following Entity data migration façade codeunits are available:</p> <ul> <li> <p>COD6110 (<strong>GL Acc. Data Migration Facade</strong>)</p> </li> <li> <p>COD6111 (<strong>Vendor Data Migration Facade</strong>)</p> </li> <li> <p>COD6112 (<strong>Customer Data Migration Facade</strong>)</p> </li> <li> <p>COD6113 (<strong>Item Data Migration Facade</strong>)</p> </li> <li> <p>COD6114 (<strong>Ex. Rate Data Migration Facade</strong>)</p> </li> </ul> <h2 id="references">References:</h2> <p>Façade pattern on Wikipedia: <a href="https://en.wikipedia.org/wiki/Facade_pattern">https://en.wikipedia.org/wiki/Facade_pattern</a></p>Docs: Discovery Eventhttps://alguidelines.dev/docs/navpatterns/patterns/discovery-event/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/discovery-event/ <p><em>by waldo</em></p> <h1 id="abstract">Abstract</h1> <p>The &ldquo;Discovery Event&rdquo; pattern is a way for a generic functionality, to call out to other functionalities that want to make use of it, by raising an event, so that they have an event to subscribe to. This is usually done to set itself up within the generic app.</p> <h1 id="the-problem">The problem</h1> <p>Let&rsquo;s suppose you have a generic piece of functionality, that hooks into lots of places (modules) in your application. To set this up, you might have to hook into all these parts of the application. Well, this pattern turns this setup around: let all the different modules set itself up in the generic app by raising a &ldquo;discovery event&rdquo;.</p> <h1 id="usage">Usage</h1> <p>The pattern is most easily described when you look at an example. This example is an actual usage of the pattern within the application, in page <strong>Service Connections.</strong></p> <p><a href="ServiceConnections.jpg"><img src="ServiceConnections.jpg" alt=" "></a></p> <p>The goal of this functionality is to:</p> <ul> <li>List all the different connections to external services,</li> <li>Have a central place to navigate to the corresponding setup of the service.</li> </ul> <p>The functionality (<strong>Service Connections</strong>) itself, is not aware of the state nor setup nor any context of all the different services in the list. All it does is:</p> <ul> <li>It raises an event as an opportunity for all services within the NAV application to subscribe to,</li> <li>It has a public function <strong>InsertServiceConnection</strong> that the subscribers can use to register itself at the Service Connection.</li> </ul> <p>The event <strong>OnRegisterServiceConnection</strong> is raised when the page (1279 - <strong>Service Connections</strong>) is opened.</p> <p>One example of a subscription is the SMTP setup. In Codeunit 400 you&rsquo;ll find the subscriber function <strong>HandleSMTPRegisterServiceConnection</strong> which subscribes to this discovery event, and calls the <strong>InsertServiceConnection</strong> to register itself.</p> <h1 id="description">Description</h1> <p>The main idea of this pattern is: &ldquo;Discover the settings, the context, the records, &hellip; which I need for my functionality&rdquo; or &ldquo;Discover the configuration for my functionality&rdquo;. In any case, &ldquo;discover&rdquo; is the main idea. It&rsquo;s a pattern where using both publishers and subscribers in one application makes a lot of sense.<br> Let&rsquo;s break down to the steps that are needed to implement the pattern.</p> <h2 id="step-1-publish-the-event">Step 1: Publish the event</h2> <p>In the below example, I create a table <strong>Module Status</strong> with a published event <strong>OnDiscoverModuleStatuses</strong>.</p> <p><a href="Pic2.jpg"><img src="Pic2.jpg" alt=" "></a></p> <p>You see that I also include the sender. This way, I will be able to access the methods on my table (which I use as a class). Obviously, other patterns can be applied here as well, like the Argument Table pattern.</p> <h2 id="step-2-raise-the-event-on-the-right-place">Step 2: Raise the event on the right place</h2> <p>When you publish an event, it should obviously be raised somewhere in the code as well. In the below example, I want to raise the event simply by a method which I want to call from a page. So I create a global function where I raise the event:</p> <p><a href="Pic2b.jpg"><img src="Pic2b.jpg" alt=" "></a></p> <h2 id="step-3-create-one-or-more-global-functions-so-that-your-subscriber-can-call-into-your-functionality-to-configure-set-up-or-do-whatever-it-needs-to-do-to-make-itself-discoverable">Step 3: Create one or more global functions, so that your subscriber can call into your functionality to configure, set up, or do whatever it needs to do to make itself discoverable</h2> <p>The generic functionality that I want to call, should be part of the main class - in this case the <strong>Module Discovery</strong> class, or better, the table (<strong>Module Status</strong>). In this table, I create this global function, because I want to make it available for the subscribers:</p> <p><a href="Pic3.jpg"><img src="Pic3.jpg" alt=" "></a><br> The business logic doesn&rsquo;t really matter for this pattern. This is obviously dependent on the functionality where you would like to implement the pattern.</p> <h2 id="step-4-subscribe-from-the-places-in-the-app-to-this-event-use-the-global-functions">Step 4: subscribe from the places in the app to this event, use the global function(s)</h2> <p>This could be anywhere. Any module within your vertical, of within the main application, can subscribe to the event. In the example below, I create the subscriber in Codeunit80, as I was interested in the status of the Sales-module in default NAV.<br> The exact place of the subscriber is up to you. The main message is that it&rsquo;s part of the module that wants to subscribe, and not part of the <strong>Module Status</strong> module in the application.<br> Here is the subscriber (and one small helper function):</p> <p><a href="Pic4.jpg"><img src="Pic4.jpg" alt=" "></a><br> You see I can use the &ldquo;sender&rdquo; as a normal Record-variable. I access the previously created global function to &ldquo;register&rdquo; this sales-module.</p> <h1 id="microsoft-dynamics-nav-versions">Microsoft Dynamics NAV Versions</h1> <p>This pattern only works with Microsoft Dynamics <strong>NAV 2016 and up.</strong></p>Docs: Documenthttps://alguidelines.dev/docs/navpatterns/patterns/document/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/document/ <p><em>By Xavier Garonnat, knk Ingénierie (France), xgaronnat@knk.fr</em></p> <h2 id="abstract">Abstract</h2> <p>A document structure contains a header and a set of lines. Each line is linked to the header and could have common data with header.</p> <h2 id="description">Description</h2> <p>This pattern should be used as a basis to build any document, showing a header and multiple lines in the same page. Basically, a document is at least composed of two tables and three pages, as shown below:</p> <p><a href="0005.Document-Pattern-UML-Class-Diagram.jpg"><img src="0005.Document-Pattern-UML-Class-Diagram.jpg" alt=" "></a></p> <h2 id="usage">Usage</h2> <p>You should use it any time you have to capture and store a document.</p> <h2 id="example">Example</h2> <p>To build this example from scratch, you will need:</p> <ul> <li>Two tables, one for the header (called &ldquo;Document Header&rdquo;), and one for the document lines (called &ldquo;Document Line&rdquo;). Each document will be composed of &ldquo;1 to N&rdquo; line(s).</li> <li>Three pages, one for the header, one for the subpage (lines), and the last for the document list obviously.Table &ldquo;Document Header&rdquo;</li> </ul> <p><strong>Table &ldquo;Document Header&rdquo;</strong>: Is the &ldquo;header&rdquo; table of your document (like Sales Header, Purchase Header, Transfer Header &hellip;)</p> <ul> <li>Add a field &ldquo;No.&rdquo; (Code 20): Should be the first field and primary key of your documents, to be driven by Serial No. (See corresponding design pattern)</li> </ul> <p>For this sample, I just added a &ldquo;Sell-to Customer No.&rdquo; to this table. Don&rsquo;t forget to manage deletion of lines with trigger OnDelete().</p> <p><strong>Table &ldquo;Document Line&rdquo;</strong>: will store the lines of the document</p> <ul> <li>Add a field &ldquo;Document No.&rdquo; (Code 20): Should be the first field and is related to table &ldquo;Document Header&rdquo;: set TableRelation to your &ldquo;Document Header&rdquo; table</li> <li>Add a field &ldquo;Line No.&rdquo; (Integer): this field will be populated automatically by the subpage Page (see AutoSplitKey)</li> </ul> <p>First (Primary) Key must be &ldquo;Document No.,Line No.&rdquo;. On table properties, set PasteIsValid to No (to avoid copying/pasting lines, will be implemented by &ldquo;Copy document&rdquo;, another pattern).</p> <p>For my sample, I just add a couple of fields: &ldquo;Item No.&rdquo; and &ldquo;Quantity&rdquo; to this table (just copy/paste standard fields from &ldquo;Sales Line&rdquo; table and delete trigger code, this will insure that each field will be well designed)</p> <p><strong>Page &ldquo;Document Subpage&rdquo;</strong>: will display the lines in the main form, and will be in charge of assigning line number automatically.</p> <p>Create the page for table &ldquo;Document Line&rdquo; with the wizard by selecting the ListPart template, add all yours fields except the primary key (&ldquo;Document No.&rdquo; and &ldquo;Line No.&rdquo;).</p> <p>Then edit the properties:</p> <ul> <li>Set AutoSplitKey, DelayedInsert and MultipleNewLines to Yes: this combination will make your subpage work as required.</li> <li>AutoSplitKey is used to set NAV calculate the last field of the key (&ldquo;Line No.&rdquo;) with proper numbers (10000, 20000&hellip;).</li> </ul> <p>Set caption to &ldquo;Lines&rdquo;. Save your page, we will use it on the next step.</p> <p><strong>Page &ldquo;Document&rdquo;</strong>: will display the document, and the lines with subpage.</p> <p>Create the page for &ldquo;Document Header&rdquo; Table with the wizard by selecting the Document template:</p> <ul> <li>Add a General FastTab</li> <li>Add all the revelant fields for the user (or at least &ldquo;No.&rdquo;)</li> <li>Click Finish to close the wizard</li> </ul> <p>Then simply add your subpage as new line in the designer, and adjust the property &ldquo;SubFormPerLink&rdquo; with &ldquo;Document No.=FIELD(No.)&rdquo; to link header and lines :</p> <p><a href="2086.Design-Pattern-Document-SubPage-Properties.png"><img src="2086.Design-Pattern-Document-SubPage-Properties.png" alt=" "></a></p> <p><strong>Page &ldquo;Document List&rdquo;:</strong> Use the Page wizard to create a List page based on the Document table and add fields, FactBox (RecordLinks, Notes&hellip;), etc.</p> <p>Once created:</p> <ul> <li>Set Editable to No on the List</li> <li>CardPageID to Page &ldquo;Document&rdquo; to enable New/Edit/&hellip; Pane actions.</li> </ul> <p>Save our page and add it to the Role Page &ldquo;Order Processor Role Center&rdquo; for example.</p> <p>Now, observe how &ldquo;Line No.&rdquo; is calculated on the first line, and when inserting a new line between the first and second one.</p> <p>Code sample (copy link to your browser) : <a href="https://knk1fr-my.sharepoint.com/personal/xgaronnat_knk_fr/_layouts/15/guestaccess.aspx?guestaccesstoken=hL0P%2fyQ1ZreY5KlSPc%2b8dHrO4zjUkqQbg8DnGSbgd1Y%3d&amp;docid=02b3cb93e1ff1459380891795fb8441fc">https://knk1fr-my.sharepoint.com/personal/xgaronnat_knk_fr/_layouts/15/guestaccess.aspx?guestaccesstoken=hL0P%2fyQ1ZreY5KlSPc%2b8dHrO4zjUkqQbg8DnGSbgd1Y%3d&amp;docid=02b3cb93e1ff1459380891795fb8441fc</a></p> <h2 id="nav-usages">NAV Usages</h2> <p>So many: Sales Order, Purchase Order, Transfer Order, Assembly Order&hellip;</p> <p>For posted document, it&rsquo;s quite similar, but you don&rsquo;t have to setup subpage properties like AutoSplitKey, used for data entry purpose only (and your pages content should be mainly read-only / non editable).</p> <h2 id="ideas-for-improvement">Ideas for improvement</h2> <ul> <li>A new property like &ldquo;AutoSplitStartNumber&rdquo;, enabled if AutoSplitKey=Yes, default value with &lt;10000&gt;. Allow to change the numbers of created line.</li> <li>Be able to copy/paste header AND lines or import header and line from an Excel file.</li> </ul> <h2 id="when-it-should-not-be-used">When it should not be used</h2> <p>This pattern is mainly used for Documents, and may not be used directly for Master data or any other table (Setup, Supplemental, etc&hellip;).</p> <h2 id="related-topics">Related Topics</h2> <p>Use Series No. Pattern for your documents, and Copy Document to implement document duplication.</p> <h2 id="references">References</h2> <p>Walkthrough: Creating a Document Page : <a href="http://msdn.microsoft.com/en-us/library/dd338599(v=nav.71).aspx" title="http://msdn.microsoft.com/en-us/library/dd338599(v=nav.71).aspx">http://msdn.microsoft.com/en-us/library/dd338599(v=nav.71).aspx</a><br> <div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"> <iframe src="https://www.youtube.com/embed/S9cRD2D4c0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" allowfullscreen title="YouTube Video"></iframe> </div> </p>Docs: Easy Update Of Setup Or Supplementary Informationhttps://alguidelines.dev/docs/navpatterns/patterns/easy-update-of-setup-or-supplementary-information/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/easy-update-of-setup-or-supplementary-information/ <p><em>Originally by Anders Larsen at Microsoft Development Center Copenhagen</em></p> <h2 id="abstract">Abstract</h2> <p>Users or the administrator must regularly update setup or supplementary information in the day-to-day business, such as setting up a new type of customer. This setup task often arrives when their focus is on registration and execution instead of setup.</p> <p>The navigation experience around these extra steps is often quite troublesome and time-consuming. To enable users to easily perform the needed update, a guide often gives the best support.</p> <p>To guide users, we can prompt them with a dialog on which they can update the setup or supplementary information instantly and easily, so that they can proceed with the business task without being side-tracked.</p> <h2 id="usage">Usage</h2> <p>Define two functions in the setup or supplementary table: One for verifying if the needed information is available, and another for exposing the page that contains the fields that the user must update.</p> <p>Call the code. For example:</p> <pre tabindex="0"><code>Local IsXAvailable : Boolean If field X &lt;&gt; &#39;&#39; then Exit(True) Exit(false) VerifyAndSetX If IsXAvailable then Exit; If Confirm(&#39;Field X is missing a value. Do you want to update it now?&#39;) then Open the card page in edit mode If not IsXAvailable then Error(Field X is missing a value. Please correct it.) </code></pre><p>The calling code</p> <pre tabindex="0"><code>.. SetupTable.VerifyAndSetX .. </code></pre><h2 id="nav-specific-example">NAV Specific Example</h2> <p>In the <strong>Sales &amp; Receivables Setup</strong> table (311) for the DK version, the following procedures have been added:</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="display:flex;"><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>IsOIOUBLPathAvailable<span style="color:#ce5c00;font-weight:bold">(...) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">Procedure</span><span style="color:#f8f8f8;text-decoration:underline"> </span>VerifyAndSetOIOUBLPath<span style="color:#ce5c00;font-weight:bold">(...) </span></span></span></code></pre></div><p>The code in the <strong>Sales &amp; Receivables Setup</strong> table can now be called directly from the related processing codeunit, such as the <strong>Sales-Post + Print</strong> codeunit (82).</p> <p>Were the code is called:</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">(</span>&#34;EAN No.&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span>&lt;&gt;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SalesSetup<span style="color:#ce5c00;font-weight:bold">.</span>VerifyAndSetOIOUBLPathSetup<span style="color:#ce5c00;font-weight:bold">(</span>SalesHeader<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Document Type&#34;<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></span></code></pre></div><p>If the setup is not updated properly, the user is prompted to update it as follows.</p> <p><a href="0654.easy-update-1.png"><img src="0654.easy-update-1.png" alt=" "></a></p> <p>Choosing <strong>Yes</strong> opens the related setup page.</p> <p><a href="4024.easy-update-2.png"><img src="4024.easy-update-2.png" alt=" "></a></p> <h2 id="nav-usages">NAV Usages</h2> <ul> <li>Report 206, <strong>Sales invoice</strong></li> <li>Table 79, <strong>Company Information</strong></li> <li>In OIOUBL fields (DK version) during posting/printing of a sales invoice.</li> </ul> <h2 id="ideas-for-improvement">Ideas for Improvement</h2> <p>Make a more generic platform implementation that launches the corresponding card page for Rec on Rec.testfield with an asterisk mark for the field that needs a proper value.</p> <h2 id="related-topics">Related Topics</h2> <p>The anti-pattern is to do a testfield on a field that is not in the table that you are currently updating.</p> <p>The test field message can often be confusing because the pages are often named differently than the tables, which can lead to misunderstanding and context-switching.</p> <div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"> <iframe src="https://www.youtube.com/embed/oeASJN-zqTo" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" allowfullscreen title="YouTube Video"></iframe> </div>Docs: Encapsulate Local Functionalityhttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/encapsulate-local-functionality/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/encapsulate-local-functionality/ <p>Any function used local must be defined as local.</p>Docs: END ELSE Pairhttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/end-else-pair/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/readability/end-else-pair/ <p>The END ELSE pair should always appear on the same line.</p> <p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OppEntry<span style="color:#ce5c00;font-weight:bold">.</span>FIND<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#39;-&#39;</span><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></span><span style="display:flex;"><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>SalesCycleStage<span style="color:#ce5c00;font-weight:bold">.</span>FIND<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#39;-&#39;</span><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:#204a87;font-weight:bold">BEGIN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#204a87;font-weight:bold">END</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OppEntry<span style="color:#ce5c00;font-weight:bold">.</span>FIND<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#39;-&#39;</span><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></span><span style="display:flex;"><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>SalesCycleStage<span style="color:#ce5c00;font-weight:bold">.</span>FIND<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#39;-&#39;</span><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:#204a87;font-weight:bold">BEGIN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">END</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span></code></pre></div>Docs: Error Message Processinghttps://alguidelines.dev/docs/navpatterns/patterns/error-message-processing/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/error-message-processing/ <p><em>By Jesper Schulz at Microsoft Development Center Copenhagen</em></p> <p>Note: This pattern describes new functionality which makes it possible to generalize the <a href="https://alguidelines.dev/navpatterns/1-patterns/journal-error-processing/">Journal Error Processing</a> pattern.</p> <h2 id="abstract">Abstract</h2> <p>Missing, invalid or incomplete data is a common issue during data processing in NAV. This article describes how to collect all error messages during processing using the error message component and present them to the user in a unified way, which enables the user to correct the errors efficiently. By leveraging the integrated error message logging functions, you can log a message with a single line of code and present it to the user with another one-liner.</p> <h2 id="description">Description</h2> <p>This article describes how to use the Error Message component in NAV, which in short gives you the possibility to:</p> <ol> <li>Link an error message to the page which enables you to resolve the problem.</li> <li>Assemble all error messages in one central view instead of having to encounter them one by one.</li> </ol> <p>Validating data is a common task during data processing in NAV. Unfortunately, validation is often done using NAV&rsquo;s integrated ERROR and TESTFIELD functions, which halt execution of the process. The user will then have to locate the invalid / missing data, correct it and reinitiate the process, possibly running into the next error, making the cycle repeat itself. This can be a very tedious, time-consuming and frustrating process. The error message component aims at improving this experience by providing a lightweight framework for error message logging and this article will explain how to leverage this functionality in your code. By doing so, all error messages are gathered during (pre-)processing and are finally presented to the user. The user then has the possibility to click on the error message, which will open the record where the invalid / missing data is located, thereby enabling the user to correct all mistakes efficiently, from one central place and in one go.</p> <p>The example below comes from a Mexican localization, where the user has to export financial balances and transactions into an XML file for government audit purposes. In order to generate valid files, some mandatory data needs to be entered in the system. By leveraging the error message component, the user will be presented with the following page, if missing or invalid data was discovered:</p> <p><a href="image001.png"><img src="image001.png" alt=" "></a></p> <p>By clicking on the error message, the user will be presented with the entity, where the invalid / missing data should be corrected / added. This is done by applying the related pattern <a href="https://alguidelines.dev/navpatterns/1-patterns/easy-update-of-setup-or-supplementary-information/">Easy Update of Setup or Supplementary Information</a>.</p> <p><a href="image003.png"><img src="image003.png" alt=" "></a></p> <h2 id="usage">Usage</h2> <p>In the processing function, define a temporary record of type &ldquo;Error Message&rdquo;. Use the functions on that record to populate the record with error message, a few of them being:</p> <ul> <li><strong>LogIfEmpty</strong></li> <li><strong>LogIfLengthExceeded</strong></li> <li><strong>LogIfInvalidCharacters</strong></li> <li><strong>LogIfOutsideRange</strong></li> <li><strong>LogIfGreaterThan</strong></li> <li><strong>LogIfEqualTo</strong></li> <li><strong>LogMessage</strong></li> </ul> <p>The following parameters must be provided to these functions:</p> <ul> <li><strong>Record:</strong> The record which you want to check</li> <li><strong>Field Number:</strong> The field number of the field you want to verify the value of</li> <li><strong>Condition:</strong> The condition the field must meet (e.g. length, range, valid characters)</li> <li><strong>Message Type:</strong> The type of message, which can be Error, Warning or Message</li> </ul> <p>When the processing is complete, you can check if any error messages of type &ldquo;Error&rdquo; were logged by calling the <strong>HasErrors</strong> function and you can show the list or error messages by calling the <strong>ShowErrorMessages</strong> function. You can also integrate the error messages list as a FactBox, but that is not part of this example.</p> <h2 id="nav-specific-example">NAV Specific Example</h2> <p>The code below is an example of how the error message component was used in one part of the before mentioned Mexican feature. This code iterates over all G/L Accounts and pipes information out into an XML file. While doing so, it is validated that all mandatory fields have values and meet certain conditions. And only if that is the case, is the XML document actually exported. Also notice, that an error message is logged, in case no G/L Accounts are found given the provided filters. That way, the user can be guided to setup the system correctly.</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">PROCEDURE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>ExportChartOfAccounts@<span style="color:#0000cf;font-weight:bold">1</span><span style="color:#ce5c00;font-weight:bold">(</span>Year@<span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#000;font-weight:bold">;</span>Month@<span style="color:#0000cf;font-weight:bold">1001</span><span style="color:#f8f8f8;text-decoration:underline"> </span><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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempErrorMessage@<span style="color:#0000cf;font-weight:bold">1003</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TEMPORARY</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:#0000cf;font-weight:bold">700</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempErrorMessage<span style="color:#ce5c00;font-weight:bold">.</span>ClearLog<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// only necessary if variable is global </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span>CreateXMLHeader<span style="color:#ce5c00;font-weight:bold">(</span>Document<span style="color:#000;font-weight:bold">,</span>RootNode<span style="color:#000;font-weight:bold">,</span>CatalogoNodeTxt<span style="color:#000;font-weight:bold">,</span>Namespace<span style="color:#000;font-weight:bold">,</span>Year<span style="color:#000;font-weight:bold">,</span>Month<span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;1.1&#39;</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempErrorMessage<span style="color:#ce5c00;font-weight:bold">.</span>LogIfEmpty<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">(</span>GLAccount<span style="color:#000;font-weight:bold">,</span>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span>FIELDNO<span style="color:#ce5c00;font-weight:bold">(</span>Name<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">,</span>TempErrorMessage<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Message Type&#34;<span style="color:#000;font-weight:bold">::</span>Error<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>XMLDOMManagement<span style="color:#ce5c00;font-weight:bold">.</span>AddElement<span style="color:#ce5c00;font-weight:bold">(</span>RootNode<span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;Ctas&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#000;font-weight:bold">,</span>Namespace<span style="color:#000;font-weight:bold">,</span>Node<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>XMLDOMManagement<span style="color:#ce5c00;font-weight:bold">.</span>AddAttribute<span style="color:#ce5c00;font-weight:bold">(</span>Node<span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;CodAgrup&#39;</span><span style="color:#000;font-weight:bold">,</span>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span>&#34;SAT Account Code&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#204a87;font-weight:bold">CASE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Debit/Credit&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">OF</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Debit/Credit&#34;<span style="color:#000;font-weight:bold">::</span>Debit<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>XMLDOMManagement<span style="color:#ce5c00;font-weight:bold">.</span>AddAttribute<span style="color:#ce5c00;font-weight:bold">(</span>Node<span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;Natur&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;D&#39;</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Debit/Credit&#34;<span style="color:#000;font-weight:bold">::</span>Credit<span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>XMLDOMManagement<span style="color:#ce5c00;font-weight:bold">.</span>AddAttribute<span style="color:#ce5c00;font-weight:bold">(</span>Node<span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;Natur&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;A&#39;</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempErrorMessage<span style="color:#ce5c00;font-weight:bold">.</span>LogMessage<span style="color:#ce5c00;font-weight:bold">( </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span>GLAccount<span style="color:#000;font-weight:bold">,</span>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span>FIELDNO<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Debit/Credit&#34;<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">,</span>TempErrorMessage<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Message Type&#34;<span style="color:#000;font-weight:bold">::</span>Error<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>STRSUBSTNO<span style="color:#ce5c00;font-weight:bold">(</span>GLAccountTypeErr<span style="color:#000;font-weight:bold">,</span>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Debit/Credit&#34;<span style="color:#000;font-weight:bold">,</span>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">RECORDID</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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>GLAccount<span style="color:#ce5c00;font-weight:bold">.</span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">END</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempErrorMessage<span style="color:#ce5c00;font-weight:bold">.</span>LogSimpleMessage<span style="color:#ce5c00;font-weight:bold">(</span>TempErrorMessage<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Message Type&#34;<span style="color:#000;font-weight:bold">::</span>Error<span style="color:#000;font-weight:bold">,</span>NoSATAccountDefinedErr<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>TempErrorMessage<span style="color:#ce5c00;font-weight:bold">.</span>HasErrors<span style="color:#ce5c00;font-weight:bold">(</span>TRUE<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>SaveXMLToClient<span style="color:#ce5c00;font-weight:bold">(</span>Document<span style="color:#000;font-weight:bold">,</span>Year<span style="color:#000;font-weight:bold">,</span>Month<span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;CT&#39;</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempErrorMessage<span style="color:#ce5c00;font-weight:bold">.</span>ShowErrorMessages<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></span><span style="display:flex;"><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></span></code></pre></div><p>One could also do pre-processing in a function of its own, and only if the pre-processing results in no error messages of type &ldquo;Error&rdquo; would the processing continue.</p> <h2 id="ideas-for-improvement">Ideas for improvement</h2> <p>By using this easy to use component, we have the possibility to extend this functionality going forward. A nice addition to the error message component would be the possibility to log the error messages persistently in a grouped manner, thereby allowing 3rd parties to see the issues the users bump into the most, or allowing 3rd parties to get an detailed insight into what happened, thereby enabling them to provide better support.</p>Docs: Extending the Role Center Headlineshttps://alguidelines.dev/docs/navpatterns/patterns/extending-the-role-center-headlines/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/extending-the-role-center-headlines/ <p><em>By David Bastide at Microsoft Development Center Copenhagen</em></p> <p><a href="3733.logo.png"><img src="3733.logo.png" alt=" "></a></p> <h2 id="context">Context</h2> <p>Headlines are designed as a page of type HeadlinePart containing at least one text field. The part is added to the top of Role Center pages.<br> This document provides an elegant and extensible pattern about how to extend the Role Center headlines to add your own business headlines based on your data, and display them only if relevant.</p> <h2 id="description">Description</h2> <p>The Dynamics 365 Business Central release (April 2018) introduces a new HeadlinePart page type. This page type defines a page that rotates a display of several headlines after another, in the web client. A user can also click to switch to another headline. Headlines can also include a drilldown action that will be invoked when the user clicks the headline Text of the payload can be emphasized.<br> Headlines are divided in 2 parts: the qualifier, and the payload as you can see in the figure below.</p> <p><a href="Headline.png"><img src="Headline.png" alt=" "></a></p> <p><em>Figure 1: Qualifier, Payload and emphasized text.</em></p> <h2 id="usage">Usage</h2> <p>A page part has been added to each major Role Center:</p> <ul> <li>Page 9006 Order Processor Role Center, contains Page 1441 Headline RC Order Processor</li> <li>Page 9015 Job Project Manager RC, contains Page 1443 Headline RC Project Manager</li> <li>Page 9022 Business Manager Role Center, contains Page 1440 Headline RC Business Manager</li> <li>Page 9024 Security Admin Role Center, contains Page 1445 Headline RC Administrator</li> <li>Page 9026 Sales &amp; Relationship Mgr. RC, contains Page 1444 Headline RC Relationship Mgt.</li> <li>Page 9027 Accountant Role Center, contains Page 1442 Headline RC Accountant</li> <li>Page 9028 Team Member Role Center, contains Page 1446 Headline RC Team Member</li> <li>Page 9010 Production Planner Role Center, contains Page 1447 Headline RC Prod. Planner</li> <li>Page 9016 Service Dispatcher Role Center, contains Page 1448 Headline RC Serv. Dispatcher</li> </ul> <p>You can create extensions that extend these pages to add your own headlines.<br> If no headline is added on these pages, fallback headlines will be displayed.</p> <p>The process to extend the headlines of a Role Center is simple:</p> <ol> <li>In a V2 extension, extend the pages (PAG1440 to 1446) with one or more fields you want to add as headlines. The field and its visibility should be variables that are populated in OnAfterGetRecord.</li> <li>Subscribe to the OnComputeHeadlines event from the codeunits associated with the page (same ID and name as the page). Here you can compute your headlines. You should store the result in a table in your extension, so you can quickly get the results in step 3. The computation is done in a background task, not to decrease the performance of the role center pages.</li> <li>Subscribe to the OnIsAnyExtensionHeadlineVisible event from the page. This event is used to determine if any extension has visible headlines, and if so, hide the fallback headlines. You should set the ExtensionHeadlinesVisible variable to true if your extension has headlines to display at the time of the event. Otherwise, do nothing.</li> <li>In the page, in the OnAfterGetRecord trigger, get the headline text and visibility values and copy them to your added fields.</li> </ol> <p>To format headlines, you should use Codeunit 1439 Headline Management functions:</p> <ul> <li>Truncate: to truncate a text gracefully when possible with &ldquo;&hellip;&rdquo;. For example, HeadlineManagement.Truncate(&rsquo;the text&rsquo;,6) returns &ldquo;the&hellip;&rdquo;.</li> <li>Emphasize: to emphasize part of the headline payload. Emphasized text is shown with a different style.</li> <li>GetHeadlineText: to build the headline text. You provide the headline qualifier and payload, and you get the headline in a format that will be interpreted and formatted correctly by the client. It returns false if the qualifier exceeds its maximum length (50 characters) or payload exceeds its maximum length (75 characters). In that case it will not return the headline. If the qualifier you specify is empty, the default text &ldquo;HEADLINE&rdquo; will be displayed in the qualifier area. The payload must not be empty.</li> </ul> <h3 id="examples">Examples:</h3> <h4 id="1-extending-the-page-with-a-new-headline">1. Extending the page with a new headline:</h4> <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="display:flex;"><span><span style="color:#204a87;font-weight:bold">group</span><span style="color:#ce5c00;font-weight:bold">(</span>LargestSale<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>{<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Visible<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span>LargestSaleVisible<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ShowCaption=false<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>Editable=false<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><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>LargestSaleText<span style="color:#000;font-weight:bold">;</span>LargestSaleText<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span>{<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ApplicationArea<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span>Basic<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Suite<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>DrillDown=true<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>OnDrillDown<span style="color:#ce5c00;font-weight:bold">() </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusHeadlineMgt<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;Essential Bus. Headline Mgt.&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusHeadlineMgt<span style="color:#ce5c00;font-weight:bold">.</span>OnDrillDownLargestSale<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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>}<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>}<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><h4 id="2-subscribing-to-the-oncomputeheadlines-event-and-computing-headlines">2. Subscribing to the OnComputeHeadlines event, and computing headlines</h4> <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="display:flex;"><span>[EventSubscriber<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">ObjectType</span><span style="color:#000;font-weight:bold">::</span><span style="color:#204a87;font-weight:bold">Codeunit</span><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:#000;font-weight:bold">::</span>&#34;Headline RC Business Manager&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;OnComputeHeadlines&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<span style="color:#ce5c00;font-weight:bold">)</span>]<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>OnComputeHeadlinesBusinessManager<span style="color:#ce5c00;font-weight:bold">() </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// [...] compute headline, and init the EssentialBusinessHeadline record </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></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>ShowHeadline<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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:#8f5902;font-style:italic">// not enough data to compute headline </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>HeadlineManagement<span style="color:#ce5c00;font-weight:bold">.</span>GetHeadlineText<span style="color:#ce5c00;font-weight:bold">( </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span><span style="color:#4e9a06">&#39;Insight from last week&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>StrSubstNo<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#39;The largest posted sales invoice was for %1&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>HeadlineManagement<span style="color:#ce5c00;font-weight:bold">.</span>Emphasize<span style="color:#ce5c00;font-weight:bold">(</span>Format<span style="color:#ce5c00;font-weight:bold">(</span>CustomerLedgerEntry<span style="color:#ce5c00;font-weight:bold">.</span>Amount<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TypeHelper<span style="color:#ce5c00;font-weight:bold">.</span>GetAmountFormatWithUserLocale<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#39;$&#39;</span><span style="color:#ce5c00;font-weight:bold">)))) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Text&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>Validate<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Headline Visible&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">Modify</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></span><span style="display:flex;"><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></span></code></pre></div><h4 id="3-subscribing-to-the-onisanyextensionheadlinevisible-event">3. Subscribing to the OnIsAnyExtensionHeadlineVisible event</h4> <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="display:flex;"><span>[EventSubscriber<span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">ObjectType</span><span style="color:#000;font-weight:bold">::</span><span style="color:#204a87;font-weight:bold">Page</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Page</span><span style="color:#000;font-weight:bold">::</span>&#34;Headline RC Business Manager&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;OnIsAnyExtensionHeadlineVisible&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<span style="color:#ce5c00;font-weight:bold">)</span>]<span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>OnIsAnyExtensionHeadlineVisible<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>ExtensionHeadlinesVisible<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></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<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;Essential Business Headline&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>AtLeastOneHeadlineVisible<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:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>SetRange<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Headline Visible&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>SetFilter<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Headline Name&#34;<span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06">&#39;%1|%2|%3|%4|%5&#39;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Name&#34;<span style="color:#000;font-weight:bold">::</span>LargestOrder<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Name&#34;<span style="color:#000;font-weight:bold">::</span>LargestSale<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Name&#34;<span style="color:#000;font-weight:bold">::</span>BusiestResource<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Name&#34;<span style="color:#000;font-weight:bold">::</span>MostPopularItem<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Name&#34;<span style="color:#000;font-weight:bold">::</span>SalesIncrease<span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Name&#34;<span style="color:#000;font-weight:bold">::</span>TopCustomer<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>AtLeastOneHeadlineVisible<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">not</span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>IsEmpty<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic">// only modify the var if this extension is making some headlines visible, setting to false could override some other extensions setting the value to true </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></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>AtLeastOneHeadlineVisible<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">then</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>ExtensionHeadlinesVisible<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>true<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div><h4 id="heading"></h4> <h4 id="4-setting-the-headline-text-on-the-page">4. Setting the headline text on the page</h4> <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="display:flex;"><span><span style="color:#204a87;font-weight:bold">trigger</span><span style="color:#f8f8f8;text-decoration:underline"> </span>OnAfterGetRecord<span style="color:#ce5c00;font-weight:bold">() </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>GetHeadline<span style="color:#ce5c00;font-weight:bold">(</span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Name&#34;<span style="color:#000;font-weight:bold">::</span>LargestSale<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>LargestSaleVisible<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Visible&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>LargestSaleText<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>EssentialBusinessHeadline<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Headline Text&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div><p><a href="0724.Headline-sequence-diagram-v2.png"><img src="0724.Headline-sequence-diagram-v2.png" alt=" "></a></p> <p><em>Figure 2: Sequence diagram of headline usage</em></p> <h2 id="usages-in-nav">Usages in NAV:</h2> <ul> <li>Essential Business Headlines extension</li> </ul>Docs: Feature Localization For Data Structureshttps://alguidelines.dev/docs/navpatterns/patterns/feature-localization-for-data-structures/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/feature-localization-for-data-structures/ <p><em>Originally by Bogdan Sturzoiu at Microsoft Development Center Copenhagen</em></p> <h2 id="abstract">Abstract</h2> <p>This pattern shows a solution for integrating W1 features to pre-existing country features that use different tables to achieve similar functionality.</p> <h2 id="description">Description</h2> <p>It sometimes happens that certain features are requested in a NAV-supported country, but they are not initially considered generic enough to be included in the W1 build. This is how local features, such as Subcontracting in Italy and India, were created or specific banking and payments functionality in Italy, France, Spain, and others.</p> <p>Then, at some point in time, a decision is made to create a W1 feature that is closely related to the local functionality but uses a completely different set of tables, pages, etc. The developers now face the following problem: How to enable the newly-developed W1 feature into a country, such that the customers who are accustomed to their local structures can seamlessly continue working without completely (or immediately) switching to the W1 objects.</p> <p>This was the issue that was tackled in the NAV 2013 R2, in relation to the SEPA Credit Transfers functionality.</p> <h3 id="using-a-proxy">Using a Proxy</h3> <p>The generic Proxy pattern is &ldquo;a class functioning as an interface to something else&rdquo; (<a href="http://en.wikipedia.org/wiki/Proxy_pattern">Wikipedia</a>).</p> <p><a href="5123.Feature-localization-for-data-structures-1.png"><img src="5123.Feature-localization-for-data-structures-1.png" alt=" "></a></p> <p>Figure 1. Proxy in UML</p> <h3 id="pattern-elements">Pattern Elements</h3> <p>The NAV data model translation of the proxy pattern can be used as explained below.</p> <p>The RealSubject is the NAV data model. Variations in table structures, relationships, and numbers are particular to each country. The W1 model is the base for the country-localized data models. However, some countries have heavy localizations which cannot be directly processed by the W1 core objects.</p> <p>The proxy is a codeunit that gathers data from wherever it is stored and transforms it to fit into a standard table, which is later used across all localizations.</p> <p>The interface is the fixed form in which the data is presented to be consumed by the client.</p> <p>The client can be an XML port that is fed from the common data interface. It can also be any other data processor (a codeunit fed to another table, etc.) or data display object (page or report).</p> <h3 id="pattern-steps">Pattern Steps</h3> <ol> <li> <p>The user creates records in the local tables.</p> </li> <li> <p>The user invokes an action that must be processed using the W1 feature code.</p> </li> <li> <p>The proxy codeunit moves the data from the local tables to the W1 tables, either into a temporary or persistent set of records, as needed.</p> </li> <li> <p>The W1 code now performs the action on the W1 table data.</p> </li> </ol> <h2 id="usage">Usage</h2> <p>In NAV 2013 R2, we released the SEPA Credit Transfer functionality. It involves exporting vendor payments to an XML file that is subsequently processed by the customer&rsquo;s bank. The payments are exported from the Payment Journal page through a configurable XMLport. Therefore, the data source for these payment lines is the Gen. Journal Line table (81).</p> <p>In various countries, we already had payment export functionality, usually into flat bank files. However, the files are generated from different tables than in W1. For example, in Italy, vendor payments are handled through the Vendor Bill Header table (12181) and the Vendor Bill Line table (12182). They are the RealSubject.</p> <p>The W1 feature flow is as follows:</p> <p><a href="6052.Feature-localization-for-data-structures-2.png"><img src="6052.Feature-localization-for-data-structures-2.png" alt=" "></a></p> <p>Figure 2. W1 object call sequence</p> <p><strong>Note:</strong> CT = Credit Transfers, pain = payments initiation (the XML format used for SEPA Credit Transfers and SEPA Direct Debit).</p> <p>The key question is: Where to tap into this flow when using a local data structure. For this purpose, a proxy codeunit has been added in W1, called 1222 &ndash; SEPA CT-Prepare Source. This codeunit feeds the client (XML1000) data in a standard format (the interface is the Gen. Journal Line table (81)).</p> <p>In W1, the codeunit simply outputs the same set of general journal lines that it receives as an input:</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="display:flex;"><span>OnRun<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>Rec<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Gen. Journal Line&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>GenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>COPYFILTERS<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>CopyJnlLines<span style="color:#ce5c00;font-weight:bold">(</span>GenJnlLine<span style="color:#000;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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>CopyJnlLines<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>FromGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Gen. Journal Line&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TEMPORARY</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;Gen. Journal Line&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FromGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>GenJnlBatch<span style="color:#ce5c00;font-weight:bold">.</span>GET<span style="color:#ce5c00;font-weight:bold">(</span>FromGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Journal Template Name&#34;<span style="color:#000;font-weight:bold">,</span>FromGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Journal Batch Name&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>TempGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FromGenJnlLine<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>TempGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>INSERT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FromGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">END</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>CreateTempJnlLines<span style="color:#ce5c00;font-weight:bold">(</span>FromGenJnlLine<span style="color:#000;font-weight:bold">,</span>TempGenJnlLine<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>CreateTempJnlLines<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>FromGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Gen. Journal Line&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TEMPORARY</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;Gen. Journal Line&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#8f5902;font-style:italic">// To fill TempGenJnlLine from the source identified by filters set on FromGenJnlLine </span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>TempGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FromGenJnlLine<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span></code></pre></div><p>In a country, such as Italy, the codeunit will have the following functions:</p> <ol> <li> <p>Gets an empty set of general journal lines that carry the local payment document key as a filter on the Document No. field (as opposed to W1 that gets the real set of records to be exported). This is done so that the local data can be extracted at runtime.</p> </li> <li> <p>Selects the local payment data, for example in Italy, in the Vendor Bill Header and Vendor Bill Lines tables.</p> </li> <li> <p>Transforms the local payment data into temporary records of the Gen. Journal Line table.</p> </li> <li> <p>Outputs the temporary general journal lines that will be further processed and exported, exactly as in W1.</p> </li> </ol> <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="display:flex;"><span>OnRun<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>Rec<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Gen. Journal Line&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>GenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>COPYFILTERS<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>CopyJnlLines<span style="color:#ce5c00;font-weight:bold">(</span>GenJnlLine<span style="color:#000;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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>CopyJnlLines<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>FromGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Gen. Journal Line&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TEMPORARY</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;Gen. Journal Line&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">IF</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FromGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>GenJnlBatch<span style="color:#ce5c00;font-weight:bold">.</span>GET<span style="color:#ce5c00;font-weight:bold">(</span>FromGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Journal Template Name&#34;<span style="color:#000;font-weight:bold">,</span>FromGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Journal Batch Name&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>TempGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FromGenJnlLine<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>TempGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>INSERT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FromGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">END</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>CreateTempJnlLines<span style="color:#ce5c00;font-weight:bold">(</span>FromGenJnlLine<span style="color:#000;font-weight:bold">,</span>TempGenJnlLine<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>CreateTempJnlLines<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>FromGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Gen. Journal Line&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TEMPORARY</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;Gen. Journal Line&#34;<span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>PaymentDocNo<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>FromGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>GETFILTER<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Document No.&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VendorBillHeader<span style="color:#ce5c00;font-weight:bold">.</span>GET<span style="color:#ce5c00;font-weight:bold">(</span>PaymentDocNo<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>RESET<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>SETCURRENTKEY<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Vendor Bill List No.&#34;<span style="color:#000;font-weight:bold">,</span>&#34;Vendor No.&#34;<span style="color:#000;font-weight:bold">,</span>&#34;Due Date&#34;<span style="color:#000;font-weight:bold">,</span>&#34;Vendor Bank Acc. No.&#34;<span style="color:#000;font-weight:bold">,</span>&#34;Cumulative Transfers&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Vendor Bill List No.&#34;<span style="color:#000;font-weight:bold">,</span>VendorBillHeader<span style="color:#ce5c00;font-weight:bold">.</span>&#34;No.&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Cumulative Transfers&#34;<span style="color:#000;font-weight:bold">,</span>TRUE<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>CumulativeAmount<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:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>PrevVendorBillLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>VendorBillLine<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">TESTFIELD</span><span style="color:#ce5c00;font-weight:bold">(</span>&#34;Document Type&#34;<span style="color:#000;font-weight:bold">,</span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Document Type&#34;<span style="color:#000;font-weight:bold">::</span>Invoice<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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:#ce5c00;font-weight:bold">((</span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Vendor No.&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span>&lt;&gt;<span style="color:#f8f8f8;text-decoration:underline"> </span>PrevVendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Vendor No.&#34;<span style="color:#ce5c00;font-weight:bold">) </span><span style="color:#204a87;font-weight:bold">OR</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">(</span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Vendor Bank Acc. No.&#34;<span style="color:#f8f8f8;text-decoration:underline"> </span>&lt;&gt;<span style="color:#f8f8f8;text-decoration:underline"> </span>PrevVendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Vendor Bank Acc. No.&#34;<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:#204a87;font-weight:bold">BEGIN</span><span style="color:#f8f8f8;text-decoration:underline"> </span>InsertTempGenJnlLine<span style="color:#ce5c00;font-weight:bold">(</span>TempGenJnlLine<span style="color:#000;font-weight:bold">,</span>VendorBillHeader<span style="color:#000;font-weight:bold">,</span>PrevVendorBillLine<span style="color:#000;font-weight:bold">,</span>CumulativeAmount<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>CumulativeAmount<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Amount to Pay&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">END</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ELSE</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>CumulativeAmount<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">+=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Amount to Pay&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>PrevVendorBillLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>VendorBillLine<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span>InsertTempGenJnlLine<span style="color:#ce5c00;font-weight:bold">(</span>TempGenJnlLine<span style="color:#000;font-weight:bold">,</span>VendorBillHeader<span style="color:#000;font-weight:bold">,</span>PrevVendorBillLine<span style="color:#000;font-weight:bold">,</span>CumulativeAmount<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>SETRANGE<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Cumulative Transfers&#34;<span style="color:#000;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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>FINDSET<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">THEN</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">REPEAT</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">TESTFIELD</span><span style="color:#ce5c00;font-weight:bold">(</span>&#34;Document Type&#34;<span style="color:#000;font-weight:bold">,</span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Document Type&#34;<span style="color:#000;font-weight:bold">::</span>Invoice<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span>InsertTempGenJnlLine<span style="color:#ce5c00;font-weight:bold">(</span>TempGenJnlLine<span style="color:#000;font-weight:bold">,</span>VendorBillHeader<span style="color:#000;font-weight:bold">,</span>VendorBillLine<span style="color:#000;font-weight:bold">,</span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Amount to Pay&#34;<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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">UNTIL</span><span style="color:#f8f8f8;text-decoration:underline"> </span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>NEXT<span style="color:#f8f8f8;text-decoration:underline"> </span>=<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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>InsertTempGenJnlLine<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>TempGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TEMPORARY</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;Gen. Journal Line&#34;<span style="color:#000;font-weight:bold">;</span>VendorBillHeader<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Vendor Bill Header&#34;<span style="color:#000;font-weight:bold">;</span>VendorBillLine<span style="color:#f8f8f8;text-decoration:underline"> </span><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;Vendor Bill Line&#34;<span style="color:#000;font-weight:bold">;</span>AmountToPay<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">Decimal</span><span style="color:#ce5c00;font-weight:bold">) </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"> </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">WITH</span><span style="color:#f8f8f8;text-decoration:underline"> </span>TempGenJnlLine<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">DO</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></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>INIT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Journal Template Name&#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><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Journal Batch Name&#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><span style="color:#4e9a06">&#39;&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Document Type&#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>&#34;Document Type&#34;<span style="color:#000;font-weight:bold">::</span>Payment<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Document 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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Vendor Bill List No.&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Line 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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Line No.&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Account 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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Vendor No.&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Account Type&#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>TempGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Account Type&#34;<span style="color:#000;font-weight:bold">::</span>Vendor<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Bal. Account Type&#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>TempGenJnlLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Bal. Account Type&#34;<span style="color:#000;font-weight:bold">::</span>&#34;Bank Account&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Bal. Account 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>VendorBillHeader<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Bank Account No.&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Applies-to Ext. Doc. 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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;External Document No.&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>Amount<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>AmountToPay<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Applies-to Doc. Type&#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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Document Type&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Applies-to Doc. 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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Document No.&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Currency Code&#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>VendorBillHeader<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Currency Code&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Due Date&#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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Due Date&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Posting Date&#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>VendorBillHeader<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Posting Date&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Recipient Bank Account&#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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Vendor Bank Acc. No.&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>Description<span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">:=</span><span style="color:#f8f8f8;text-decoration:underline"> </span>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>Description<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>&#34;Message to Recipient&#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>VendorBillLine<span style="color:#ce5c00;font-weight:bold">.</span>&#34;Description 2&#34;<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span>INSERT<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div><p>The derived local feature flow is as follows:</p> <p><a href="3058.Feature-localization-for-data-structures-3.png"><img src="3058.Feature-localization-for-data-structures-3.png" alt=" "></a></p> <p>Figure 3. The local country object flow</p> <p>As we can see from the diagram, this solution allows integration of the local and W1 features with a minimum amount of changes in W1 code. The only two differences are:</p> <ol> <li> <p>The entry point of the flow is the local table/page.</p> </li> <li> <p>Codeunit 1222 is overloaded to prepare general journal lines from the local records.</p> </li> </ol> <h2 id="nav-usages">NAV Usages</h2> <p>The data mapping technique has been used for the SEPA Credit Transfer feature, and will be used in subsequent local integration projects.</p> <h2 id="ideas-for-improvement">Ideas for improvement</h2> <p>A weak point for this pattern is the need to set a filter on the empty journal line in order to retrieve the local data when exporting from a local page. This can cause problems if the size of the local table document number is larger than the Document No. field (ID 20) in the Gen. Journal line table (81).</p> <p>Also, there is a strong need for thorough testing when using this pattern, because there might be differences in the behavior of the local table and table 81. Whatever is acceptable for the local table may not be acceptable for the W1 table. A deep functional analysis is needed to see if the local export feature uses the same constraints as the W1 feature.</p>Docs: FIELDCAPTION and TABLECAPTIONhttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/localizability/fieldcaption-and-tablecaption/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/localizability/fieldcaption-and-tablecaption/ <p>For user messages, errors etc., use FIELDCAPTION not FIELDNAME and TABLECAPTION not TABLENAME.</p> <p>Reason:</p> <ol> <li>The correct translation will be automatically used.</li> <li>If the caption/name changes, then there will be a single point of change needed.</li> </ol> <p>Bad code</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="display:flex;"><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>CONFIRM<span style="color:#ce5c00;font-weight:bold">(</span>UpdateLocationQst<span style="color:#000;font-weight:bold">,</span>TRUE<span style="color:#000;font-weight:bold">,</span>FIELDNAME<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Location Code&#34;<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">,</span><span style="color:#ce5c00;font-weight:bold">...) </span></span></span></code></pre></div><p>Good code</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="display:flex;"><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>CONFIRM<span style="color:#ce5c00;font-weight:bold">(</span>UpdateLocationQst<span style="color:#000;font-weight:bold">,</span>TRUE<span style="color:#000;font-weight:bold">,</span>FIELDCAPTION<span style="color:#ce5c00;font-weight:bold">(</span>&#34;Location Code&#34;<span style="color:#ce5c00;font-weight:bold">)</span><span style="color:#000;font-weight:bold">,</span><span style="color:#ce5c00;font-weight:bold">...) </span></span></span></code></pre></div>Docs: FIELDERRORhttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/ux/fielderror/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/ux/fielderror/ <p>Never use FIELDERROR with a period as it is automatically inserted.</p> <p>Bad code</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="display:flex;"><span>InvalidValue@<span style="color:#0000cf;font-weight:bold">1025</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TextConst</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;ENU=is invalid.&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>Cust<span style="color:#ce5c00;font-weight:bold">.</span>FIELDERROR<span style="color:#ce5c00;font-weight:bold">(</span>&#34;No.&#34;<span style="color:#000;font-weight:bold">,</span>InvalidValue<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></span></code></pre></div><p>Good code</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="display:flex;"><span>InvalidValue@<span style="color:#0000cf;font-weight:bold">1025</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TextConst</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;ENU=is invalid&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span>Cust<span style="color:#ce5c00;font-weight:bold">.</span>FIELDERROR<span style="color:#ce5c00;font-weight:bold">(</span>&#34;No.&#34;<span style="color:#000;font-weight:bold">,</span>InvalidValue<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></span></code></pre></div>Docs: FINDSET FINDFIRST FINDLASThttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/findset-findfirst-findlast/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/design/findset-findfirst-findlast/ <p>FINDSET, FIND(&rsquo;+&rsquo;) or FIND(&rsquo;-&rsquo;) should only be used when NEXT is used and vice versa.</p> <p>Bad code</p> <pre><code>IF Cust.FIND('-') THEN ERROR(CustIsBlockErr) </code></pre> <p>Good code</p> <pre><code>IF Cust.FINDFIRST THEN ERROR(CustIsBlockErr) </code></pre> <p>Bad code</p> <pre><code>IF Cust.FINDFIRST THEN REPEAT ... UNTIL Cust.NEXT = 0; </code></pre> <p>Good code</p> <pre><code>IF Cust.FINDSET THEN REPEAT ... UNTIL Cust.NEXT = 0; </code></pre>Docs: Global Text Constantshttps://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/localizability/global-text-constants/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/3-cal-coding-guidelines/localizability/global-text-constants/ <p>Declare Text Constant as global variables.</p> <p>Bad code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">PROCEDURE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>GetRequirementText@<span style="color:#0000cf;font-weight:bold">6</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">Text</span>[<span style="color:#0000cf;font-weight:bold">50</span>]<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RequirementOptionsTxt@<span style="color:#0000cf;font-weight:bold">1002</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TextConst</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;ENU=Shipment,Receive,Pick,Put-Away&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div><p>Good code</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="display:flex;"><span><span style="color:#204a87;font-weight:bold">VAR</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"> </span>RequirementOptionsTxt@<span style="color:#0000cf;font-weight:bold">1002</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">TextConst</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;ENU=Shipment,Receive,Pick,Put-Away&#39;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#ce5c00;font-weight:bold">... </span></span></span><span style="display:flex;"><span><span style="color:#ce5c00;font-weight:bold"></span><span style="color:#204a87;font-weight:bold">PROCEDURE</span><span style="color:#f8f8f8;text-decoration:underline"> </span>GetRequirementText@<span style="color:#0000cf;font-weight:bold">6</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">Text</span>[<span style="color:#0000cf;font-weight:bold">50</span>]<span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline"> </span></span></span><span style="display:flex;"><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></span></code></pre></div>Docs: Hookshttps://alguidelines.dev/docs/navpatterns/patterns/hooks/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/hooks/ <p><em>By Eric Wauters (<a href="http://www.waldo.be" title="waldo's blog">waldo</a>), Partner-Ready-Software</em></p> <h2 id="abstract">Abstract</h2> <p>As a partner, adding new code to NAV means interfering with code shipped by Microsoft. Minimize your footprint of changes in Microsoft code, so that, when a new NAV version is shipped, you avoid conflicts and upgrade impact. The core NAV code is the &ldquo;danger zone&rdquo; - the less you touch it, the happier your upgrade will be.</p> <h2 id="description">Description</h2> <p>When doing development over years, by different developers with different mindsets, the standard codebase gets changed a lot, adding multiple lines of code, adding local and global variants, adding or changing keys, changing existing business logic, &hellip; . In other terms, the standard text objects are being changed all over the place.. .</p> <p>After years, it&rsquo;s not clear why a change was done, and what was the place where the change was intended to be done. And the latter is quite important in an upgrade process, when code in the base product is being refactored: if the exact place of the posting of the Customer Entry is being redesigned to a separate number, the first thing I need to know, is that I did a certain change at the place: &ldquo;where the posting of the Customer Entry starts&rdquo;. The definition of that place, we call a &ldquo;Hook&rdquo;.</p> <p>By minimizing the code in already existing application objects, you will make the upgrade process much easier, and all customization business logic will be grouped in new objects. When using atomic coding, it will be very readable what is being customized on a certain place in an existing part of the application.</p> <p>To minimize the impact of customizations, the idea of hooks is:</p> <ul> <li>First of all, name the places in the already existing code where customization is needed;</li> <li>Second, place your business logic completely outside the already existing application code.</li> </ul> <p>I recommend to use this concept on:</p> <ul> <li>All objects of the default applications that need to be changed</li> <li>On objects that should not hold any business logic (like tables, pages, XMLPorts)</li> </ul> <h2 id="usage">Usage</h2> <p><strong>Step 1</strong> - if it doesn&rsquo;t exist yet - you create your Hook Codeunit. As the name assumes .. this is always a codeunit. We apply the following rules to it:</p> <ul> <li>One Hook always hooks into one object. Which basically means that I will only declare this new codeunit in one other object (which is its parent object)</li> <li>The naming convention is: &ldquo;The_Original_Object_Name Hook&rdquo;. Naming conventions are important, just to find your mapped object, and also to be able to group the Hooks.</li> </ul> <p><strong>Step 2</strong>, you create the hook, which is basically a method (function) in your codeunit. The naming is important:</p> <ul> <li>The naming of the hook should NOT describe what it is going to do (So, examples like &ldquo;CheckMandatoryFields&rdquo;, &ldquo;FillCustomFields&rdquo; should not be used as a hook)</li> <li>The naming of the hook should describe WHERE the hook is placed, not what the hook will be doing (as nobody is able to look into the future .. :-))</li> <li>To help with the naming, it is a good convention to use the &ldquo;On&rdquo;-prefix for these triggers. This way, it&rsquo;s very clear what are hooks, and what aren&rsquo;t..</li> </ul> <p><strong>Step 3</strong>, it&rsquo;s time to hook it to its corresponding object and right place in the business logic of that object. You do this by declaring your codeunit as a global in your object, and using the created hook function on its place in the business logic. This way, these one-liners apply:</p> <ul> <li>A Hook Codeunit is only used once in one object only (its corresponding object)</li> <li>A Hook (function) is used only once in that object. As a consequence, changing the parameters has no consequence: you only need to change one function-call</li> <li>The codeunit is declared as a global. That exact global is the only custom declaration in the existing object .. Everything else is pushed to the hook-codeunit.</li> </ul> <p><strong>Step 4</strong>, implement your business logic in the hook. Do this in the most atomic way, as there is a good chance that this same hook is going to be used for other business logic as well. Best is to use a one-line-function-call to business logic, so that the Hook Function itself stays readable.</p> <h2 id="example">Example</h2> <p>Suppose, we want to add business logic just before posting a sales document. In that case, we have to look for the most relevant place, which is somewhere in the &ldquo;Sales-Post&rdquo; codeunit. So:</p> <p><strong>Step 1</strong>: create codeunit &ldquo;Sales-Post Hook&rdquo;</p> <p><a href="5383.HookPattern1.png"><img src="5383.HookPattern1.png" alt=" "></a></p> <p><strong>Step 2</strong>: create the hook function &ldquo;OnBeforePostDocument&rdquo;</p> <p><a href="6378.HookPattern2.png"><img src="6378.HookPattern2.png" alt=" "></a></p> <p><strong>Step 3</strong>: declare a global in the &ldquo;Sales-Post&rdquo;-codeunit, called &ldquo;SalesPostHook&rdquo;. Then, call the Hook Function that you created in Step 2 in the right place.</p> <p><a href="8156.HookPattern3.png"><img src="8156.HookPattern3.png" alt=" "></a></p> <p><strong>Step 4</strong>: implement the business logic, by calling out to a new function. And implement the test-codeunit.</p> <p><a href="8875.HookPattern4.png"><img src="8875.HookPattern4.png" alt=" "></a></p> <h2 id="consequences">Consequences</h2> <p>This pattern can be used in all cases to put business logic. But I see three possible approaches</p> <ol> <li>You only declare the most important and most used hooks <ul> <li>This way, you limit the amount of objects and hooks to only a few in the default product</li> <li>For example, only the OnBeforePostSalesHeader, OnBeforeReleaseSalesDocument, .. And no field validation or such&hellip;</li> </ul> </li> <li>Only at objects of the default application which you are customizing. <ul> <li>This way, you don&rsquo;t want to create hooks for your own objects, only default existing objects.</li> </ul> </li> <li>(recommended) You create hooks on all places you don&rsquo;t want to write business logic, and on all existing objects which you would like to customize. <ul> <li>This is a very consistent way of working, as in any case, your business logic ends up in either a hook, or in its corresponding objects from a specific design pattern. But you know that the entry point is always a hook.</li> <li>You know what to expect in any case, both changed business logic in existing code and business logic in newly created code is entered from a hook.</li> </ul> </li> </ol> <h2 id="related-topics">Related Topics</h2> <p>Atomic coding: It&rsquo;s important that the hook function is readable in the most extreme way. For this, we recommend to use the &ldquo;Atomic Coding&rdquo; concept.</p> <p>See here a comparison / extension of hooks : <a href="http://www.waldo.be/2016/02/29/nav-2016-hooks-or-events/">http://www.waldo.be/2016/02/29/nav-2016-hooks-or-events/</a></p>Docs: Surrogate keys using Autoincrement Patternhttps://alguidelines.dev/docs/navpatterns/patterns/implementation-of-surrogate-keys-using-autoincrement-pattern/Mon, 01 Jan 0001 00:00:00 +0000https://alguidelines.dev/docs/navpatterns/patterns/implementation-of-surrogate-keys-using-autoincrement-pattern/ <p><em>By <a href="http://mvp.microsoft.com/en-us/mvp/Soren%20Klemmensen-5001002" title="Soren Klemmensen">Soren Klemmensen</a>, <a href="http://partner-ready-software.com/" title="Partner-Ready-Software"><em>Partner-Ready-Software</em> </a> &amp; <a href="http://www.360visibility.com/" title="360 Visibility">360 Visibility</a></em></p> <h2 id="abstract">Abstract</h2> <p>This Pattern is meant to create generic &amp; reusable links between tables. The goal is to have an easy generic way to link a generically designed sub table to a record on a main table which can be used for other links too.</p> <p>To minimize the impact of customizations and to keep modules as generic and reusable as possible the idea of the Implementation of surrogate keys using AutoIncrement pattern is:</p> <ul> <li>To create a generic and reusable auto generated link (A Surrogate Key), Immune to natural key data &amp; requirement changes, on a main table with minimum impact on the table.</li> <li>To create generic and reusable sub tables that effortless can be reused anywhere in the application.</li> </ul> <h2 id="description">Description</h2> <p>Over years of development many things are repeated across different implementation and even inside the same application. A typical example could be adding comments to an area just as it is done in Microsoft Dynamics NAV multiple times. There can be reasons for doing this again and again, but not only does this need to be maintained and upgraded over the years, but all the implementations of comments also needs to be tested separately. If a standard and generic comment could be developed and a generic way of connecting it to a main table this could be resolved. This is exactly what this pattern is trying accomplish.</p> <p><a href="0458.Figure-1.PNG"><img src="0458.Figure-1.PNG" alt=" "></a></p> <p><em>Figure 1: Table structure for linking a Document Header and Line Table with a Document Comment Table.</em></p> <p><a href="0638.Figure-2.PNG"><img src="0638.Figure-2.PNG" alt=" "></a></p> <p><em>Figure 2: Table Structure for linking a Master Data Table with a Master Data Comment Table</em></p> <p>A typical way of linking a table to master data or to a document has been to use the primary key of the table being linked to. This causes some issues as the linked table now is designed specifically for the main table and it functionality cannot be reused. In case of renames the linked table needs to be renamed too which is costly in processing. Code also needs to be added on the delete trigger of the table to ensure that the attached records get removed if needed which increases the over all footprint of any change.</p> <p><a href="0333.Figure-3.PNG"><img src="0333.Figure-3.PNG" alt=" "></a></p> <p><em>Figure 3: A Generic Way of creating a Comment table and linking it in a generic way to the main table no matter what this table might be. The Unique Record Identifier on the main tables is an Integer with AutoIncrement set to yes.</em></p> <p>It is recommended using this pattern in all tables which need sub tables unless specific reasons exists for not doing this.</p> <h2 id="usage">Usage</h2> <p><strong>Step 1</strong>: Create a generic Unique Record Identifier in the main table</p> <p>The Pattern is implemented by adding a Field (I have called it Unique Record Identifier for this article) in a table (the main Table) where links are needed to be established to. Set the Property Data Type to Integer, Editable to No &amp; AutoIncrement to Yes.</p> <p><strong>Step 2</strong>: Create a generic link-able sub table.</p> <p>Create a new table (Sub Table) which you would like to be reusable with a primary key containing</p> <ul> <li>Table No. of Data Type Integer</li> <li>Unique Record Identifier of Data Type Integer</li> <li>A 3 field for allowing multiple entries to exist per record in the main table if so needed. This could be a Line No. of Data Type Integer or a Code field of Data Type Code(10) and so on.</li> </ul> <p>The important part here is that the 2 or 3 first fields in the tables primary key is the Table No. and the Unique Record Identifier. If a 3rd field was added to allow for multiple entries to exist per record in the main table this should also be included in the primary key.</p> <p>Make sure to also add any other fields containing the information you wish to store as needed to the table.</p> <p>The sub table will be immune to renames from the main table as the main tables primary key is not used in the primary key of the sub table. The Insert, Modify and Rename triggers are not causing any issues and only the delete trigger will need to be considered. This can be dealt with generically from the OnDatabaseDelete trigger in Codeunit 1. I would recommend to use a Hook Pattern for this.</p> <p><strong>Step 3</strong>: Create a page showing the sub table information.</p> <p>Now create a page showing the data in the sub table.</p> <p><strong>Step 4</strong>: Add an Action or factbox.</p> <p>Create an action or factbox on the pages showing the main table data linking to the subpage with Table ID filtered to a constant of the Table No. of the main table and the Unique Record Identifier of the sub table filtering to the Unique Record Identifier of the main table.</p> <p><strong>Step 5</strong>: Create a Hook for Function OnDatabaseDelete in Codeunit 1 ApplicationManagement if one doesn&rsquo;t already exist. See the Hook pattern.</p> <p><strong>Step 6</strong>: Create a code to delete records in the Sub table if a main table record is deleted if this is required. This function needs to be called from the Hook created in Step 5.</p> <h2 id="nav-specific-example"><strong>NAV Specific Example</strong></h2> <p>Let&rsquo;s assume we would like to create comment for a larger number of very different tables in the system.</p> <p><strong>Update the Customer table (Step 1)</strong>: Go to table 18 Customer and add Field 50000 Unique Record Identifier. Set the Property Data Type to Integer, Editable to No &amp; AutoIncrement to Yes. Save the changes.</p> <p><a href="1488.Example-Figure-1.png"><img src="1488.Example-Figure-1.png" alt=" "></a></p> <p>_<a href="4682.Example-Figure-2.png"><img src="4682.Example-Figure-2.png" alt=" "></a></p> <p><strong>Create Comment table (Step 2)</strong>: Create a new table called Comment. Add 3 fields Table No., Unique Record Identifier &amp; Line No. all of Data Type Integer. Make these 3 fields into the primary key for the table. Add a 4 field called Comment with Data Type Text(80). Save the changes.</p> <p><a href="4532.Example-Figure-3.png"><img src="4532.Example-Figure-3.png" alt=" "></a></p> <p><strong>Create the Comments page (Step 3)</strong>: Start the page wizard and create a Page based on table comment created above as a List only showing the Comment field. Set AutoSplitKey property to Yes on the page.</p> <p>_<a href="2068.Example-Figure-4.png"><img src="2068.Example-Figure-4.png" alt=" "></a>_</p> <p><strong>Update the Customer Card (Step 4)</strong>: Add an action to the Customer Card to open the Comments. Go to Actions and create an action called Smart Comment. Populate the properties RunObject, RunPageView and RunPageLink as see in the picture below.</p> <p><a href="https://alguidelines.dev/cfs-file.ashx/__key/communityserver-wikis-components-files/00-00-00-00-42/0552.Example-Figure-5.png"><img src="0552.Example-Figure-5.png" alt=" "></a></p> <p><strong>Create a hook OnDatabaseDelete (Step 5)</strong>:</p> <p>Create a codeunit 50000 called &ldquo;ApplicationManagement Hook&rdquo; with one function called OnAfterOnDatabaseDelete taking the parameter RecRef of Data Type RecordRef. Add it as a global variable to Codeunit 1 ApplicationManagement and call the function as the last line in OnDatabaseDelete. Please read about the hook pattern before implementing it.</p> <p><a href="https://alguidelines.dev/cfs-file.ashx/__key/communityserver-wikis-components-files/00-00-00-00-42/4477.Example-Figure-6.png"><img src="4477.Example-Figure-6.png" alt=" "></a></p> <p><strong>Create the code needed to delete comments linked to a deleted record (Step6)</strong>:</p> <p>Create a DeleteComments function taking the RecRef of Data Type RecordRef and add the code as shown blow.</p> <p><a href="https://alguidelines.dev/cfs-file.ashx/__key/communityserver-wikis-components-files/00-00-00-00-42/1884.Example-Figure-7.png"><img src="1884.Example-Figure-7.png" alt=" "></a></p> <p>It is assumed in this example for simplicity that the Field 50000 is reserved across the entire application for the Unique Record Identifier as defined in Step 1.</p> <p>The comments are now fully working if we look away from the fact that we did not deal with a few things specific to Sales orders like RecreateSalesLines function, Archiving and Copy Document. All of which can easily be dealt with.</p> <p>These comments are now completely reusable everywhere else in the system. Sales Document is a perfect example as the primary keys of the Sales Header and the Sales line are both different from the customer and normally we would not be able to use the comments header or the line. All that needs to be done is adding the Field 50000 Unique Record Identifier to the Sales Header &amp; Sales Line (Disregarding the posted documents in this example) and creating the actions on the Page Actions with the needed filters. Deletion is already handled of comments no matter what the main table might be.</p> <p>Looking at the main table the Unique Record Identifier is also completely reusable for any other linking needed.</p> <p>Other ideas for use of this pattern could be. An Error table, Tags, Dynamically defined fields and Generic fact boxes. Only the imagination sets limits for its use.</p> <p>Upgrade wise there can be an impact if data is moved out of tables to be reinserted again because of a change to a database structure. This will cause the Unique Record Identifier to change, unless steps are taken to avoid this, and the links will need to be reestablished.</p> <p>Other risks could be if Transfer Fields are used and data is being copied unintentionally.</p> <h2 id="nav-usages">NAV Usages</h2> <p>This is a new pattern not currently used in Microsoft Dynamics NAV.</p> <h2 id="ideas-for-improvement">Ideas for improvement</h2> <p>The reason for doing it this way is that you now can reuse your code again and again with only creating the same link on other tables instead of building it from scratch each time reducing testing needed and improving the quality of the overall product.</p> <h2 id="consequences-when-it-should-not-be-used">Consequences (When it should not be used)</h2> <p>This can be used on any table when linking anything to it that can be considered a generic module which can be reused. That said it should not be used in cases where there is a risk of tables growing so much that performance could be impacted. There are ways to reduce performance impact when using high volume tables, but that is outside the scope of this pattern.</p> <h2 id="related-topics">Related Topics</h2> <p>This is related to the hook pattern as far as they both try to reduce the footprint changes have on the standard application, by creating reusable ways to interact with the standard code. That said the hook pattern is more about hooking the functionality to existing while this pattern is more about creating reusable ways of creating functionality.</p>