<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Chatgpt on Wingate365</title><link>https://blog.wingate365.com/tags/chatgpt/</link><description>Recent content in Chatgpt on Wingate365</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Wed, 29 Mar 2023 07:32:44 +0000</lastBuildDate><atom:link href="https://blog.wingate365.com/tags/chatgpt/index.xml" rel="self" type="application/rss+xml"/><item><title>To Validate or Not to Validate: Line validation in Dynamics 365 Business Central Documents</title><link>https://blog.wingate365.com/2023/03/to-validate-or-not-to-validate-line.html</link><pubDate>Sun, 05 Mar 2023 19:54:00 +0000</pubDate><guid>https://blog.wingate365.com/2023/03/to-validate-or-not-to-validate-line.html</guid><description>&lt;p&gt;This is a short note on how to add further validation to the sales or purchase document lines in Dynamics 365 Business Central with a small AL code extension.&amp;nbsp;&lt;/p&gt;&lt;p&gt;There are a number of validations operating in the background for sales and purchase lines. Sometimes you need to add to this, in this example I'll build a small app to meet the following requirement.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;ul style="text-align: left;"&gt;&lt;li&gt;Prevent sales lines with zero value&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;This is a great starting point for building apps &lt;a href="https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-get-started"&gt;https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-get-started&lt;/a&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To meet this requirement I'll use the OnAfterInsert trigger which will carry out the checks after the system already validated at the database level.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;a href="https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/triggers-auto/tableextension/devenv-onafterinsert-tableextension-trigger"&gt;https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/triggers-auto/tableextension/devenv-onafterinsert-tableextension-trigger&lt;/a&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here is the example code:&lt;/div&gt;&lt;script src="https://emgithub.com/embed-v2.js?target=https%3A%2F%2Fgithub.com%2Fandywingate%2Fd365bc-validatesalesline%2Fblob%2Fmain%2FSalesLine.TableExt.al&amp;amp;style=default&amp;amp;type=code&amp;amp;showBorder=on&amp;amp;showLineNumbers=on&amp;amp;showFileMeta=on&amp;amp;showFullPath=on&amp;amp;showCopy=on"&gt;&lt;/script&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Lets see what ChatGPT has to say about this&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Pretty handy!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;What if we want more? I asked to validate in a different way: "Please rewrite the code to also prevent the job and job task from being blank"&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;
&lt;script src="https://gist.github.com/andywingate/dbd1b85d1b65c34cd4b5e47454291c52.js"&gt;&lt;/script&gt;
&lt;div&gt;Looks good, I liked the way it also updated the error message, very handy. Would need testing of course.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The original simple .app and code can be found here&amp;nbsp;&lt;a href="https://github.com/andywingate/d365bc-validatesalesline"&gt;https://github.com/andywingate/d365bc-validatesalesline&lt;/a&gt;&lt;/div&gt;</description></item></channel></rss>