<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Kasper Mørch's Blog about Microsoft Dynamics 365 Business Central]]></title><description><![CDATA[This blog is about development and automated testing for Dynamics 365 Business Central using Microsoft AL and Visual Studio Code.
You may also find a few posts ]]></description><link>https://businesscentral.kaspermoerch.dk</link><generator>RSS for Node</generator><lastBuildDate>Thu, 21 May 2026 19:45:57 GMT</lastBuildDate><atom:link href="https://businesscentral.kaspermoerch.dk/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to test for errors]]></title><description><![CDATA[Not all test scenarios should have a positive outcome (sunny path). Sometimes we want to test that a certain scenario fails with an error (rainy path).
The challenge is that the nature of tests in the Business Central Test Framework is that errors re...]]></description><link>https://businesscentral.kaspermoerch.dk/how-to-test-for-errors</link><guid isPermaLink="true">https://businesscentral.kaspermoerch.dk/how-to-test-for-errors</guid><category><![CDATA[Automated Testing]]></category><dc:creator><![CDATA[Kasper Mørch]]></dc:creator><pubDate>Thu, 22 Jun 2023 17:05:01 GMT</pubDate><content:encoded><![CDATA[<p>Not all test scenarios should have a positive outcome (sunny path). Sometimes we want to test that a certain scenario fails with an error (rainy path).</p>
<p>The challenge is that the nature of tests in the Business Central Test Framework is that errors result in a test failure.</p>
<p>To overcome this challenge we have to tell the Test Framework that an error is expected. This also means that no error is unexpected.</p>
<p>This is exactly what the <code>asserterror</code> keyword is for. It inverts the error mechanism and encapsulates the error allowing us to then assert that we get the expected error as shown the example below.</p>
<pre><code class="lang-plaintext">[Test]
procedure "Test for error"()
begin
   asserterror Error('An expected error');
   LibraryAssert.ExpectedError('An expected error');
end;

var
   LibraryAssert: Codeunit "Library Assert";
</code></pre>
<h3 id="heading-errors-are-still-erros">Errors are still erros</h3>
<p>Even though the error mechanism is inverted when using <code>asserterror</code> the actual error will still occur. The consequence of this is that rollbacks will happen as usual.</p>
<p>In the example below we insert some data, test for an error with <code>asserterror</code> and then try to modify the data we inserted. However, the modification will fail with an error because the inserted data has been removed by the rollback.</p>
<pre><code class="lang-plaintext">[Test]
procedure "Errors are still errors"()
var
   Customer: Record Customer;
begin
   Customer.Insert();
   asserterror Error('An expected error');
   Customer.Modify(); // An error with be thrown by this statement
end;
</code></pre>
<p>If this behavior is unwanted all we need to do is add a commit and everything will work as expected.</p>
<pre><code class="lang-plaintext">[Test]
procedure "Errors are still errors"()
var
   Customer: Record Customer;
begin
   Customer.Insert();
   Commit();
   asserterror Error('An expected error');
   Customer.Modify(); // No error is thrown because the insert was committed.
end;
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Installing the Test Toolkit]]></title><description><![CDATA[There are several options for installing the Test Toolkit in a Microsoft Dynamics 365 Business Central container. Which option is available to you depends on whether you are creating a new container or you already have one up and running.
Include Tes...]]></description><link>https://businesscentral.kaspermoerch.dk/installing-the-test-toolkit</link><guid isPermaLink="true">https://businesscentral.kaspermoerch.dk/installing-the-test-toolkit</guid><category><![CDATA[Automated Testing]]></category><dc:creator><![CDATA[Kasper Mørch]]></dc:creator><pubDate>Thu, 23 Dec 2021 14:01:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/EJe6LqEjHpA/upload/v1640268075931/C6wotXR2g.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>There are several options for installing the Test Toolkit in a Microsoft Dynamics 365 Business Central container. Which option is available to you depends on whether you are creating a new container or you already have one up and running.</p>
<h3 id="heading-include-test-toolkit-on-container-creation">Include Test Toolkit on container creation</h3>
<p>The Test Toolkit can be included upon creation of your container through the <a target="_blank" href="https://github.com/microsoft/navcontainerhelper">BcContainerHelper</a> PowerShell Module.</p>
<p>There are three switches that you can set in order to control which parts of the Test Toolkit will be installed:</p>
<ul>
<li><p><code>-includeTestToolkit</code> is the main switch and is required to enable the installation of the Test Toolkit. If specified alone it will cause a full install of the Test Toolkit which also includes Microsofts test suites.</p>
</li>
<li><p><code>-includeTestFrameworkOnly</code> will only install the Test Framework. The Test Framework contains the required dependencies for developing automated tests.</p>
</li>
<li><p><code>-includeTestLibrariesOnly</code> will install the Test Framework including a wide selection of libraries created by Microsoft.</p>
</li>
</ul>
<p>Here is an example of how to create a container with the Test Toolkit included:</p>
<pre><code class="lang-plaintext">$username = "admin"
$password = ConvertTo-SecureString "#LetMeIn123" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
$artifactUrl = Get-BCArtifactUrl
New-BcContainer "AUTOMATEDTESTS" -artifactUrl $artifactUrl -Credential $credential -updateHosts -accept_eula -includeTestToolkit -includeTestFrameworkOnly
</code></pre>
<h3 id="heading-install-the-test-toolkit-on-an-existing-container">Install the Test Toolkit on an existing container</h3>
<p>When you already have a container running but want to start using the Test Toolkit you can install it with the <a target="_blank" href="https://github.com/microsoft/navcontainerhelper">BcContainerHelper</a> PowerShell Module.</p>
<p>Running the command <code>Import-TestToolkitToBcContainer</code> command will install the Test Toolkit in the specified container.</p>
<p>It is also possible to specify the <code>-includeTestFrameworkOnly</code> and <code>-includeTestLibrariesOnly</code> switches as mentioned above.</p>
<p>Here is an example of how to install the Test Toolkit in an existing container:</p>
<pre><code class="lang-plaintext">Import-TestToolkitToBcContainer "AUTOMATEDTESTS" -includeTestLibrariesOnly
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Setting up CC and BCC Email Recipients]]></title><description><![CDATA[Edit as of May 16th, 2024:With the release of Business Central 24, the discontinuation of Microsoft Invoicing is now complete, meaning this approach is no longer supported.
It is possible to add one or more CC or BCC addresses when sending emails fro...]]></description><link>https://businesscentral.kaspermoerch.dk/setting-up-cc-and-bcc-email-recipients</link><guid isPermaLink="true">https://businesscentral.kaspermoerch.dk/setting-up-cc-and-bcc-email-recipients</guid><dc:creator><![CDATA[Kasper Mørch]]></dc:creator><pubDate>Mon, 20 Dec 2021 08:34:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/S3Lig53867M/upload/v1639989152852/x6MvdT8w5.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong><mark>Edit as of May 16th, 2024:<br />With the release of Business Central 24, the discontinuation of Microsoft Invoicing is now complete, meaning this approach is no longer supported.</mark></strong></p>
<p>It is possible to add one or more CC or BCC addresses when sending emails from Dynamics 365 Business Central.</p>
<p>If you add the url parameter "page=2128" you will be redirected to a page where you can add CC and BCC addresses.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1639988887307/xxvymJ3W0.png" alt="image.png" /></p>
<p>Note that the CC and BCC addresses will be added to <strong>all</strong> outgoing emails.</p>
]]></content:encoded></item><item><title><![CDATA[Special Characters in Translations]]></title><description><![CDATA[If special characters are not shown correctly in the Windows client, it might be because the objects were compiled with the wrong code page.
To fix this you need to run C/Side with the unicode paramter:
finsql.exe unicode=1
Then open the relevant dat...]]></description><link>https://businesscentral.kaspermoerch.dk/special-characters-in-translations</link><guid isPermaLink="true">https://businesscentral.kaspermoerch.dk/special-characters-in-translations</guid><dc:creator><![CDATA[Kasper Mørch]]></dc:creator><pubDate>Thu, 09 Dec 2021 13:40:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/BVyNlchWqzs/upload/v1639989447433/BmWwm8427.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If special characters are not shown correctly in the Windows client, it might be because the objects were compiled with the wrong code page.</p>
<p>To fix this you need to run C/Side with the unicode paramter:</p>
<pre><code>finsql.exe unicode<span class="hljs-operator">=</span><span class="hljs-number">1</span>
</code></pre><p>Then open the relevant database and compile all objects.</p>
<p>Even though the characters might not be shown correctly inside C/Side the compilation will be done using unicode and the special characters will now be shown correctly in the client.</p>
]]></content:encoded></item></channel></rss>