Member states of the European Union expose thier VAT (Tax Registration Number) validation to the masses via VIES. Below is an example using Amazon’s VAT registration details against the service on the EU website.
Here the member state to which the organisation belongs has been selected, then the VAT number has been entered allowing for validity check. In the next screen we see the response to clicking the verifty button.
– open data goodness! - now for the cool bit…
If you hunt under the FAQ, buried in there, it turns out there is a SOAP webservice available that does the same thing!
This WSDL URL is our key to some great functionality for Dynamics GP.
In Visual Studio For Dynamics GP Add-in project create a WCF reference to the VIES SOAP webservice.
In your proxy class you will find checkVatPortTypeClient.CheckVat as a method. This is the one we are after, supply the parameters and by reference the results will be returned
We then create a visual studio add in event handler to fire on the user leaving the Tax Registration field of relevant forms in GP. Hence we can validate the VAT number the user has entered! So in our Add in project in the event handler for the options window Tax Registration Field we handle the event.
Public Shared Sub TaxRegNumberValidateBeforeOriginal(Sender As Object, e As System.ComponentModel.CancelEventArgs)
Dim CustomerMaintOptionsForm As MicrosoftDynamicsGpModifiedDictionary.RmCustomerMaintenanceForm.RmCustomerOptionsWindow = _
If Not CustomerMaintOptionsForm.TaxRegistrationNumber.IsEmpty Then
If Windows.Forms.MessageBox.Show("Remember to update address intrastats field too." & vbCrLf & "Do you want to validate this number?", "Validate?", _
Windows.Forms.MessageBoxButtons.YesNo, Windows.Forms.MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Using oVATNumberValidationForm As New VATNumberValidation
oVATNumberValidationForm.VatNumber = CustomerMaintOptionsForm.TaxRegistrationNumber.Value
If oVATNumberValidationForm.ShowDialog() = vbOK Then
e.Cancel = True
e.Cancel = True
CustomerMaintOptionsForm.TaxRegistrationNumber.Value = oVATNumberValidationForm.VatNumber
Catch ex As Exception
Windows.Forms.MessageBox.Show("TaxRegNumberValidateBeforeOriginal" & vbCrLf & ex.ToString)
Using the address of the company being looked up, we select the state code from the combo box (could automate this), we then supply to the webservice on hitting the validate button. A windows form shows the results of the validation to the user. If the supplied details fail validation we show the windows form to the user so they can correct the issue and try again. On closing the form we update the Tax Registration Field.
Private Sub btnValidate_Click(sender As System.Object, e As System.EventArgs) Handles btnValidate.Click
If txtVATNumber.Text.Length > 0 And cbxMemberState.SelectedIndex <> -1 Then
Dim oStringBuilder As New Text.StringBuilder
Dim o As New VATChecker.checkVatPortTypeClient
Dim ovalid As Boolean
Dim oName As String = String.Empty
Dim oAddress As String = String.Empty
Dim oResult As String = String.Empty
Dim oSelectedCountryCode As String = CStr(cbxMemberState.SelectedItem).Split(CChar(("-")))(0)
oResult = o.checkVat(oSelectedCountryCode, txtVATNumber.Text, ovalid, oName, oAddress)
If ovalid Then
txtResults.Text = oStringBuilder.ToString
txtResults.Text = "INVALID"
Windows.Forms.MessageBox.Show("Enter VAT number and select member state")
This is a rough example, the webservice call can be asynchronous, the country code derived from addresses, more error checking and neater presentation of the results, window could be derived from Dex windows for familiar Dex styles, however this post is more about what is possible in twenty mins with Dynamics GP plugins and data opened to the world via webservices.
Optionally, if the details of the your company are passed to the service (state & VAT number), then a consultation number is returned which is proof that you have looked up and validated the VAT number should you be challenged on that fact, but this is optional.
Different countries have maintenance windows where this service will not work check the VIES website for details