The previous post GP2010 SP3 Enhanced Intrastats VAT number format wrong IE (Ireland) and others…identified an issue with the validation on the Tax Registration Number in the Intrastat Setup Window for Dynamics GP addresses. Ireland have introduced a new format for VAT numbers that allows two alpha characters, the following is the full specification:
1234567X, 1X23456X, 1234567XX, (8 or 9 characters. Includes one or two alphabetical characters (last, or second and last, or last 2))
If a VAT number is entered in the format 1234567XX, GP will not accept it, preventing the user for leaving that window until a valid format is entered. This was raised with Fargo, but nothing came back from them and it is still a problem today in version GP2013R2. One would expect a SQL table keyed on country code, that holds regular expressions to feed this validator, thus they can be easily changed when this sort of event occurs. Instead it looks like the validation is hard coded in the Dexterity scripts.
Well, if you can’t get a job done properly, do it yourself. Our sales team are starting to hit this issue more often now that the new codes have been available for a little while and more new companies have been allocates these new format codes. This ear ache called for a fix…
Script logging tells us that the validator function is:
'eiProc_IsValidFormat_GBTaxRegNumber()', 0, "IE", "1234567RH"
Wonderful - this looks like a quick and easy fix…
Run the DAG against the Intrastat module to get the.NET assemblies, in my case and with my install that is:
"C:\Program Files (x86)\Microsoft Dynamics\GP2013 VS Tools SDK\DAG.exe" 2788 /M /O
"C:\Program Files (x86)\Microsoft Dynamics\GP2013 VS Tools SDK\DAG.exe" 2788 /F /O
Reference the assemblies in the addin project,
Now create an after script “trigger” (.NET event handler) against this script in GP on the init of the addin.
'----------------------- EnhancedIntrastat -----------------------------
AddHandler EnhancedIntrastat.Functions.EiProcIsValidFormatGbTaxRegNumber.InvokeAfterOriginal, AddressOf AfterEiProcIsValidFormatGbTaxRegNumber
Write a regular expression to validate the field. Try the regular expression tester extension for Visual Studio, go to the gallery (extensions and updates) to install it, then test the expression.
This is not a optimum expression, but this post is intended for audience that may familiar with regular expressions, so it is in a form that is accessible to be easily understood.
Finally write the override method called by the after event of that script to change the result to true or false for IE based on the corrected regular expression validation.
Private Sub AfterEiProcIsValidFormatGbTaxRegNumber(sender As Object, e As
'Override the built in check and replace with the correct checking
If e.inParam1 = "IE" Then
e.result = True
e.result = False
Catch ex As Exception
Compile, deploy, test and the form will now correctly validate the new numbers. The regular expression will actually go into a SQL table as the next iteration of this code, the network support team will then be able to add more exceptions to the validation rules in the future without a deployment, should any other countries change formats.