{"id":770,"date":"2010-10-26T00:05:50","date_gmt":"2010-10-26T07:05:50","guid":{"rendered":"http:\/\/45.63.48.66\/?p=770"},"modified":"2019-05-02T14:51:44","modified_gmt":"2019-05-02T21:51:44","slug":"what-is-in-your-dynamics-nav-toolbelt-find-inconsistency-in-gl-entries-when-posting","status":"publish","type":"post","link":"https:\/\/gotcal.com\/index.php\/2010\/10\/what-is-in-your-dynamics-nav-toolbelt-find-inconsistency-in-gl-entries-when-posting\/","title":{"rendered":"What is in your Dynamics NAV toolbelt? Find inconsistency in G\/L Entries when posting"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-774\" title=\"ohno\" src=\"\/wp-content\/uploads\/2010\/10\/ohno.jpg\" alt=\"\" width=\"236\" height=\"191\">One of the most difficult errors in NAV to troubleshoot is: &#8220;The transaction cannot be completed because it will cause inconsistencies in the G\/L Entry table&#8221;. In a standard, unmodified database it is usually related to tax\/rounding issues. And in customized databases, it can be all sorts of issues.<\/p>\n<p>I have seen all kinds of workarounds for figuring out the data\/transaction that causes the inconsistency. Most of them have been way to complicated, doing all kinds of modifications to the posting codeunit, or looking up uncommitted records through sophisticated SQL queries. Until the post by Rashed Amini back in 2007 (can be found here on <a href=\"http:\/\/www.mibuso.com\/forum\/viewtopic.php?t=22748\">MIBUSO<\/a>), there was no real good solution to it.<\/p>\n<p>Unfortunately there is still a lot of developers that are not aware of this priceless trick, so let&#8217;s look into how he solved the issue of looking at the transactions that caused the inconsistency.<\/p>\n<p><!--more--><\/p>\n<p><a href=\"http:\/\/45.63.48.66\/wp-content\/uploads\/2010\/10\/inconsistency.jpg\" rel=\"lightbox[770]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-776\" title=\"inconsistency\" src=\"http:\/\/45.63.48.66\/wp-content\/uploads\/2010\/10\/inconsistency-300x77.jpg\" alt=\"\" width=\"300\" height=\"77\" srcset=\"https:\/\/gotcal.com\/wp-content\/uploads\/2010\/10\/inconsistency-300x77.jpg 300w, https:\/\/gotcal.com\/wp-content\/uploads\/2010\/10\/inconsistency.jpg 717w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>First of all, this uses the Single Instance feature of codeunits. Single Instance for codeunits is basically reusing the variables for multiple instances of the object. The official documentation puts it like this:<\/p>\n<blockquote><p>When you set this property to Yes on a codeunit, all codeunit variables that  use this codeunit use the same instance. That is, all codeunit variables of this  codeunit use the same set of internal variables when the code is running on the  same client. The codeunit remains instantiated until you close the company.<\/p>\n<p>The following example shows how you can use the SingleInstance property.<\/p>\n<p>Two forms can connect to the same codeunit.<\/p>\n<p>On Form1:<\/p>\n<p><code>Codeunit1.SetNumber(100);<\/code><\/p>\n<p>On Form2:<\/p>\n<p><code>Number := Codeunit1.GetNumber();&nbsp;MESSAGE(Format(Number));<\/code><\/p>\n<p>The SingleInstance property in Codeunit1 is set to Yes. Form1 calls a  function on Codeunit1 and sets the parameter to 100. Codeunit1 saves this  parameter in a local variable. Form2 is now able to get the parameter value  (=100) from Codeunit1. A message is displayed.<\/p><\/blockquote>\n<p>The purpose of this, is that an instance of the object can set a value of variable, that can be accessed from another instance of the same object (codeunit).<\/p>\n<p>Another important point for single instance codeunits, is that they are not under the rules of the rollback of transactions. So even if an error happens, you can still read the values that were set in the previous rolled back transaction. This is where it becomes handy for as our little detective to finding the G\/L inconsistencies.<\/p>\n<p>Lets look at Ahmed&#8217;s actual code for the single instance codeunit:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nOBJECT Codeunit 50000 Single Instance CU\n{\nOBJECT-PROPERTIES\n{\nDate=10\/11\/07;\nTime=&#x5B; 2:50:02 PM];\nModified=Yes;\nVersion List=MOD01;\n}\nPROPERTIES\n{\nSingleInstance=Yes;\nOnRun=BEGIN\nIF NOT StoreToTemp THEN BEGIN\nStoreToTemp := TRUE;\nEND ELSE\nFORM.RUNMODAL(0,TempGLEntry);\nEND;\n\n}\nCODE\n{\nVAR\nTempGLEntry@1000000000 : TEMPORARY Record 17;\nStoreToTemp@1000000001 : Boolean;\n\nPROCEDURE InsertGL@1000000000(GLEntry@1000000000 : Record 17);\nBEGIN\nIF StoreToTemp THEN BEGIN\nTempGLEntry := GLEntry;\nIF NOT TempGLEntry.INSERT THEN BEGIN\nTempGLEntry.DELETEALL;\nTempGLEntry.INSERT;\nEND;\nEND;\nEND;\n\nBEGIN\nEND.\n}\n}\n<\/pre>\n<p>The code you need to insert into codeunit 12, is in the function FinishCodeunit():<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nFinishCodeunit()\nWITH GenJnlLine DO BEGIN\nIF GLEntryTmp.FIND('-') THEN BEGIN\nREPEAT\nGLEntry := GLEntryTmp;\nIF GLSetup.&quot;Additional Reporting Currency&quot; = '' THEN BEGIN\nGLEntry.&quot;Additional-Currency Amount&quot; := 0;\nGLEntry.&quot;Add.-Currency Debit Amount&quot; := 0;\nGLEntry.&quot;Add.-Currency Credit Amount&quot; := 0;\nEND;\nGLEntry.INSERT;\n\/\/MOD01 Start\nSingleCU.InsertGL(GLEntry);\n\/\/MOD01 End\nIF NOT InsertFAAllocDim(GLEntry.&quot;Entry No.&quot;) THEN\n<\/pre>\n<p>To use the &#8220;detective&#8221; you first run the codeunit, that will set the variable StoreToTemp to TRUE, and instantiate the codeunit as single instance.<\/p>\n<p>Next you run your posting that causes the inconsistency error. NAV will error the same way as it originally did, but now you have also written the GL Entries to our single instance codeunit, where they are stored in a temporary table.<\/p>\n<p>By running the codeunit again, you will now display a form with the temporary GL entries, and it will be easy to see why the transactions do not balance.<\/p>\n<p>Kudos go out to Ahmed Rashid for this great tip, and hopefully this blog post can get more people to know about this cool trick. I have it in my toolbelt, and have used it multiple times to troubleshoot with.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>One of the most difficult errors in NAV to troubleshoot is: &#8220;The transaction cannot be completed because it will cause inconsistencies in the G\/L Entry table&#8221;. In a standard, unmodified database it is usually related to tax\/rounding issues. And in customized databases, it can be all sorts of issues. I have seen all kinds of [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[56,3,61],"tags":[37,77,60,27,59,39,58],"class_list":["post-770","post","type-post","status-publish","format-standard","hentry","category-basic-cal","category-navision","category-toolbelt-2","tag-application","tag-navision","tag-gl-entry","tag-how-to","tag-inconsistency","tag-programming","tag-single-instance"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts\/770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/comments?post=770"}],"version-history":[{"count":8,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts\/770\/revisions"}],"predecessor-version":[{"id":1021,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts\/770\/revisions\/1021"}],"wp:attachment":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/media?parent=770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/categories?post=770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/tags?post=770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}