Irish Tax Registration Number in Dynamics GP (continued)

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))
https://www.gov.uk/vat-eu-country-codes-vat-numbers-and-vat-in-other-languages

image

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…

Fixing it

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:

'Advanced Intrastats
"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,

image

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.

image

image

This is not a optimum expression, but this post is intended for audience that may not be familiar with regular expressions, so it has been left in a form that may be more understood by onlookers.

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 
               EnhancedIntrastatDictionary.EiProcIsValidFormatGbTaxRegNumberFunction.InvokeEventArgs)
    Try
        'Override the built in check and replace with the correct checking
        If e.inParam1 = "IE" Then
            If System.Text.RegularExpressions.Regex.IsMatch(e.inParam2,
                "^(IE){0,1}[0-9]{7}([0-9][A-Z]|[A-Z]{2})|(IE){0,1}[0-9][0-9A-Z][0-9]{5}[A-Z]$") Then
                e.result = True
            Else
                e.result = False
            End If
        End If
    Catch ex As Exception
        exceptions.ExceptionHandler.ShowException(ex)
    End Try
End Sub

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.