MIAS VIES Check VAT ID in Navision / BC365

Estimated reading time: 12 minutes

Why should I check sales tax IDs (VAT ID)?

Well... because if you're reading this, you're based in Germany or Austria... and that's where EU regulations (and in some cases German or Austrian regulations) are taken seriously. Fortunately, Business Central 365 (BC365 or Navision Financials) makes this pretty easy for you - in principle.

Providers of electronic services such as antivirus program updates are obliged to charge VAT for this service. If the purchaser of these services is liable for VAT, it may be the customer and not the service provider who is liable for VAT. Therefore, the supplier can ask for the customer's VAT number to clarify whether he has to charge VAT or whether the customer has to pay VAT. If the customer does not have a valid VAT number, the service provider will charge the VAT.

And for your suppliers (but since 2025 probably also for customers, I haven't found the article again) you are simply obliged to check the VAT ID of your business partner and to document this check! Reducing bureaucracy... If your VAT ID is invalid, you can (and will) be denied input tax deduction on the purchase invoice - this applies to both domestic and foreign suppliers!

Even worse: If you invoice services (goods or services) to an industrial customer with an incorrect VAT ID, the tax office will demand the VAT from you.

If it does not comply with its obligation to check the correctness of the VAT ID number and it turns out that the VAT ID number provided by its customer is incorrect, the VAT ID number must be changed. was wrong, you must expect to pay tax arrears. To avoid this risk, a We strongly recommend checking the VAT ID number of the recipient of the delivery.

The reason is simple: more and more fraud with input tax/sales tax, e.g. the still possible and therefore still popular Sales tax carousel.

What is VIES?

VIES (VAT Information Exchange System) is a search engine (not a database!) of the European Commission. When searching via VIES, the data is retrieved from the national VAT databases. So if you check a VAT identification number in BC365 or Navision, this request from Navision first goes to VIES, VIES then queries the information system there, depending on the target country, and then returns the answer to you via REST or SOAP (as well as the request). The result is then a so-called Qualified verification of the VAT ID no., because you have checked the existence of the VAT ID number in Business Central or Navision and this also prove via the protocol but also because the name and address of the owner of the verified VAT number is logged in Business Central (or Navision) and can therefore be compared with the data you have entered. This is particularly important if an auditor or even a tax auditor has doubts about one of your debtors or creditors. Thanks to GDPdU, Idea reports these doubts to the auditor fully automatically.

What is the online VAT Information Exchange System (VIES)?

The VIES is a system for electronically validating the VAT number of traders registered in the European Union for cross-border transactions of goods or services.
If you want to check the VAT number of your customer in another Member State / Northern Ireland via the VIES web application, this request will be sent from Business Central 365 (or Navision) via a secure connection to the relevant national database to check if the number is listed there. If yes, the status „valid“ is displayed. If not, the status „invalid“ is displayed.

Depending on the applicable data protection rules, some Member States also provide the names and addresses of VAT number holders listed in the national databases.

The VAT ID is required if, for example, you make EU-wide purchases/sales as a company. To check whether the buyer is „liable for VAT“, the number can be checked directly with the EU via an API.

The search result in VIES only shows whether the VAT information is available!
Possible reasons for negative feedback:
The VAT ID number does not exist.
The VAT ID number has not yet been activated.
Registration is not yet complete

What happens if a VAT identification number is not confirmed?
If the customer states that they are registered for VAT but the check via the VIES system does not confirm this, they can request a check in addition to the tax authority in their country. Furthermore, registration may be required for cross-border transactions in the EU. The procedure varies from country to country and is beyond the scope of this guide.

These changes are not immediately updated in the national databases and therefore also not in VIES. It may be possible to verify the number „tomorrow“.

Setting up the VAT ID check (VAT IDnr check) in Navision / BC365

Navision Financials 2019R2, 2.01,3.70 etc, Navision 2013R2 etc.

There is no automated check of the VAT ID in these versions. However, this check can of course also be retrofitted here. You will find the necessary code units for the RTC versions at the end of this article. SOAP is not the first choice for the Classic Client versions, especially since SOAP has already been officially discontinued (but will still work at the beginning of 2026!). See here.
Talk to me if you need support here.
The automatic check of the VAT number can be retrofitted in any Navision version, but then simply via REST Api. If you no longer have a maintenance contract (2 new tables and 3 code units are required for the original Navision/BC365 objects), we can also do this for you directly in Navision Standard!

Navision 2015, 2016, 2017

Here you activate the check option by entering the VIES address (https://ec.europa.eu/taxation_customs/vies/services/checkVatService) in the „VAT ID no. check URL“ field in Financial Accounting under Reporting setup:

Screenshot from Navision versions 2015, 2016, 2017 for entering the URL for the VAT ID no. check with VIES

(Note: I'm not entirely sure about Navision 2015, I don't have a database ready to check right now. If this facility is missing in your Navision 2015, then the previous paragraph applies. I would appreciate a short feedback, then I can correct this paragraph if necessary).

Navision 2016, 2017 (and possibly 2015?) only saves „VAT ID exists“ and „Registered name“ and „Registered address“ in the log. If you would like to have the other fields of the successor versions here (Confirmed street, Confirmed zip code, Confirmed city and whether the confirmed address matches the address you have stored), then please contact me.. The answer from VIES is always the same, so it is „only“ a matter of making this answer visible to you.

Navision 2018, BC365 (Business Central 365)

The logic here has been extensively changed and there is now a background service for checking. Attention! The change was only partially implemented with Hotfix 35 in Navision 2018/BC14!

This service is activated under „Setting for VAT registration service“:

To make the whole thing more exciting, the actual setup page is then called

Screenshot of Navision 2018/BC14 or generally BC365 Business Central 365 for checking the VAT IDs

„Normally“ you do not have to do more than make these settings, depending on the Navision or BC365 version.

You can then click on the three dots [...] next to the VAT ID in the customer or vendor and the result of the validation will be returned:

Screenshot from Navision with a successful VAT ID check. Navision logs every check in accordance with the law

You can also have hundreds of VAT numbers checked automatically using the batch processing of VAT ID numbers.

So far, so good... But what happens when things go wrong?

Users of Navision 2015, 2016 and 2017 versions, but also Navision 2018 and BC14 are very likely to experience this error message

The remote server has returned an error: (400) Invalid request.

The connection to the remote service could not be established. The remote server has returned an error: (400) Invalid request. Service URL: https://ec.europa.eu/taxation_customs/vies/services/checkVatService

Connection to the remote service could not be established. The remote server returned an error: (400) Bad Request. Service URL: https://ec.europa.eu/taxation_customs/vies/services/checkVatService

Or the query simply returns no result / no response at all. If you use my corrections/customization, you will find the two files VatIDrequest.txt with the SOAP request and VatIDresult.txt with the SOAP response on the Navision services server under c:\temp, which often helps.

If you already have use my LOG, then you will find the request and the answers in the log.

In the case of the above error message, code units 248 (Timeout & ContentType), 249 (Type of XML analysis) must usually be updated, and the SetContentType sub-function must be added to 1290.
As end users generally do not have access to these two code units, I have not provided a detailed description here. Below you will find the source codes.

Table 226 does not exist or „The metadata object Table 226 was not found“

Completely strange! There is a Navision version in which the tables 226 and 227 and the associated pages simply do not exist! I think it only concerns version 14.0.45012.0, at least I have never received this error message in any other version. The solution is accordingly simple: Install the patches for KB375980 from the Cu35 (Cumulative Update) of version 11.0.45373 - it is sufficient if these objects are installed/updated:
Code units 1751 248 249
Menu 1010
Pages 246 247 248 249
Table 226, 227, 248, 249

Cumulative Update 35 for Microsoft Dynamics NAV 2018 (Build 45373) - Microsoft Support

Error when calling System.Xml.XmlDocumentLoad with the following message: ‚>‘ is an unexpected Token

Here you only need the CU248
SOAPWebServiceRequestMgt.SetContentType(‚text/xml; charset=utf-8‘);
to be installed:

Screenshot for the VIES/Sales Tax ID check in Navision Financials/Business Central 365 for "Error when calling System.Xml.XmlDocumentLoad with the following message (unexpected token)

Tip: Use the longer timeout right away, in older versions this is still set to 5000 (5 seconds). See the following two error messages.

TIMEOUT

In this case, the VIES query services are simply overwhelmed. Try it again later. See also „What is VIES“ at the top.

MS_MAX_CONCURRENT_REQ

Here, too, the EU servers are overloaded. You will find here and here very detailed explanations, how the whole clutter nonsense works at all... or, often better: should work 🙂

In standard Navision you will not receive any further information on these two errors, you will simply have to try again later. It often works a few minutes later. See above: With my change you will find the query and the answer in XML text form in c:\temp\, this often helps to answer exactly this question.

At night between 11 p.m. and 5 a.m., the service may be completely unavailable, as documented here:

BZSt - Confirmation of foreign VAT ID numbers

Bug fixes through AI artificial intelligence

Error with zero valuesIn older versions (e.g. NAV 2009/5.0) the report 11007 (VAT-Vies Declaration Tax-DE) cannot process zero values correctly. A hotfix is required.

Mhmnjaja... The „tip“ is technically correct... but unfortunately this has absolutely nothing to do with the VAT ID check, the mentioned report 11007 cannot even send the created XML file via SOAP or RestAPi 🙂
You can find the hotfix here:
The „VAT-Vies Declaration Tax-DE“ report (11007) does not handle the value of zero correctly in the German version of Microsoft Dynamics NAV - Microsoft Support

AuthenticationWhen using API keys (if required), the user name and password must be stored correctly in the CA (Certificate Authority).

VIES does not require any authentication.

Otherwise, the answers from Copilot, for example, are rather ... well. So as not to use the word „garbage“, I'll write „limitedly helpful“ 🙂

I have already shared my opinion about AI Artificial Intelligence in Navision here announced. But I do like using Copilot's picture function! This picture here was also taken with Copilot. Apart from that, I'm currently (February 2026) still not afraid of losing my job to some LLM/AI like ChatGPT or another 🙂

Updated code units from the 2016 version

If you have access to code units 248, 249 and 1290, I'll list the corrected contents here, so you'll already know what to do 🙂

OBJECT Codeunit 248 VAT Lookup Ext. data Hndl
{
 OBJECT-PROPERTIES
 {
 Date=09.02.26;
 Time=13:19:58;
 Modified=Yes;
 Version List=NAVW19.00;
 }
 PROPERTIES
 {
 TableNo=249;
 Permissions=TableData 249=rimd;
 OnRun=BEGIN
 VATRegistrationLog := Rec;

 LookupVatRegistrationFromWebService(TRUE);

 Rec := VATRegistrationLog;
 END;

 }
 CODE
 {
 VAR
 NamespaceTxt@1003 : TextConst '@@@={Locked};DEU=urn:ec.europa.eu:taxud:vies:services:checkVat:types;ENU=urn:ec.europa.eu:taxud:vies:services:checkVat:types';
 VATRegistrationLog@1000 : Record 249;
 VATRegistrationLogMgt@1002 : Codeunit 249;
 VatRegNrValidationWebServiceURLTxt@1001 : TextConst '@@@={Locked};DEU=http://ec.europa.eu/taxation_customs/vies/services/checkVatService;ENU=http://ec.europa.eu/taxation_customs/vies/services/checkVatService';
 MissingWebServiceURLErr@1004 : TextConst 'DEU=The VAT Registration No. Validation URL is not specified in the Financial Accounting Setup window.;ENU=The VAT Registration No. Validation URL is not specified in the General Ledger Setup window.";

 LOCAL PROCEDURE LookupVatRegistrationFromWebService@7(ShowErrors@1000 : Boolean);
 VAR
 RequestBodyTempBlob@1002 : Record 99008535;
 BEGIN
 RequestBodyTempBlob.INIT;

 SendRequestToVatRegistrationService(RequestBodyTempBlob,ShowErrors);

 RequestBodyTempBlob.Blob.EXPORT("c:\temp\VatIDresult.txt');

 InsertLogEntry(RequestBodyTempBlob);

 COMMIT;
 END;

 LOCAL PROCEDURE SendRequestToVatRegistrationService@1(VAR BodyTempBlob@1004 : Record 99008535;ShowErrors@1003 : Boolean);
 VAR
 GeneralLedgerSetup@1005 : Record 98;
 SOAPWebServiceRequestMgt@1001 : Codeunit 1290;
 ResponseInStream@1002 : InStream;
 InStream@1006 : InStream;
 ResponseOutStream@1008 : OutStream;
 BEGIN
 PrepareSOAPRequestBody(BodyTempBlob);

 BodyTempBlob.Blob.CREATEINSTREAM(InStream);

 GeneralLedgerSetup.GET;
 IF GeneralLedgerSetup. 'VAT Reg. No. Validation URL' = "" THEN
 ERROR(MissingWebServiceURLErr);
 SOAPWebServiceRequestMgt.SetGlobals(InStream,GeneralLedgerSetup. 'VAT Reg. No. Validation URL',"",'');
 SOAPWebServiceRequestMgt.DisableHttpsCheck;
 SOAPWebServiceRequestMgt.SetTimeout(60000);
 SOAPWebServiceRequestMgt.SetContentType('text/xml; charset=utf-8');
 IF SOAPWebServiceRequestMgt.SendRequestToWebService THEN BEGIN
 SOAPWebServiceRequestMgt.GetResponseContent(ResponseInStream);

 BodyTempBlob.Blob.CREATEOUTSTREAM(ResponseOutStream);
 COPYSTREAM(ResponseOutStream,ResponseInStream);
 END ELSE
 IF ShowErrors THEN
 SOAPWebServiceRequestMgt.ProcessFaultResponse('');
 END;

 LOCAL PROCEDURE PrepareSOAPRequestBody@12(VAR BodyTempBlob@1000 : Record 99008535);
 VAR
 XMLDOMMgt@1006 : Codeunit 6224;
 BodyContentInputStream@1004 : InStream;
 BodyContentOutputStream@1005 : OutStream;
 BodyContentXmlDoc@1003 : DotNet ''System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';
 EnvelopeXmlNode@1012 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 CreatedXmlNode@1001 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 BEGIN
 BodyTempBlob.Blob.CREATEINSTREAM(BodyContentInputStream);
 BodyContentXmlDoc := BodyContentXmlDoc.XmlDocument;

 XMLDOMMgt.AddRootElementWithPrefix(BodyContentXmlDoc,'checkVatApprox",'',NamespaceTxt,EnvelopeXmlNode);
 XMLDOMMgt.AddElement(EnvelopeXmlNode,'countryCode',VATRegistrationLog.GetCountryCode,NamespaceTxt,CreatedXmlNode);
 XMLDOMMgt.AddElement(EnvelopeXmlNode,'vatNumber',VATRegistrationLog.GetVATRegNo,NamespaceTxt,CreatedXmlNode);
 XMLDOMMgt.AddElement(
 EnvelopeXmlNode,'requesterCountryCode',VATRegistrationLog.GetCountryCode,NamespaceTxt,CreatedXmlNode);
 XMLDOMMgt.AddElement(
 EnvelopeXmlNode,'requesterVatNumber',VATRegistrationLog.GetVATRegNo,NamespaceTxt,CreatedXmlNode);


 CLEAR(BodyTempBlob.Blob);
 BodyTempBlob.Blob.CREATEOUTSTREAM(BodyContentOutputStream);
 BodyContentXmlDoc.Save(BodyContentOutputStream);
 BodyTempBlob.Blob.EXPORT('c:\temp\VatIDrequest.txt');
 END;

 LOCAL PROCEDURE InsertLogEntry@4(ResponseBodyTempBlob@1000 : Record 99008535);
 VAR
 XMLDocOut@1012 : DotNet ''System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';
 InStream@1009 : InStream;
 BEGIN
 ResponseBodyTempBlob.Blob.CREATEINSTREAM(InStream);
 XMLDocOut := XMLDocOut.XmlDocument;
 XMLDocOut.Load(InStream);

 VATRegistrationLogMgt.LogVerification(VATRegistrationLog,XMLDocOut,NamespaceTxt);
 END;

 PROCEDURE GetVATRegNrValidationWebServiceURL@5() : Text[250];
 BEGIN
 EXIT(VatRegNrValidationWebServiceURLTxt);
 END;

 BEGIN
 END.
 }
}

OBJECT Codeunit 249 VAT Registration Log Mgt.
{
 OBJECT-PROPERTIES
 {
 Date=09.02.26;
 Time=14:57:32;
 Modified=Yes;
 Version List=NAVW19.00;
 }
 PROPERTIES
 {
 Permissions=TableData 249=rimd;
 OnRun=BEGIN
 END;

 }
 CODE
 {

 PROCEDURE LogCustomer@1(Customer@1000 : Record 18);
 VAR
 VATRegistrationLog@1001 : Record 249;
 CountryCode@1002 : Code[10];
 BEGIN
 CountryCode := GetCountryCode(Customer. 'Country/Region Code");
 IF NOT IsEUCountry(CountryCode) THEN
 EXIT;

 InsertVATRegistrationLog(
 Customer. "VAT Registration No.",CountryCode,VATRegistrationLog. "Account Type"::Customer,Customer. "No.");
 END;

 PROCEDURE LogVendor@2(Vendor@1002 : Record 23);
 VAR
 VATRegistrationLog@1001 : Record 249;
 CountryCode@1000 : Code[10];
 BEGIN
 CountryCode := GetCountryCode(Vendor. "Country/Region Code");
 IF NOT IsEUCountry(CountryCode) THEN
 EXIT;

 InsertVATRegistrationLog(
 Vendor. "VAT Registration No.",CountryCode,VATRegistrationLog. "Account Type"::Vendor,Vendor. "No.");
 END;

 PROCEDURE LogContact@8(Contact@1000 : Record 5050);
 VAR
 VATRegistrationLog@1001 : Record 249;
 CountryCode@1002 : Code[10];
 BEGIN
 CountryCode := GetCountryCode(Contact. "Country/Region Code");
 IF NOT IsEUCountry(CountryCode) THEN
 EXIT;

 InsertVATRegistrationLog(
 Contact. "VAT Registration No.",CountryCode,VATRegistrationLog. "Account Type"::Contact,Contact. "No.");
 END;

 PROCEDURE LogVerification@3(VAR VATRegistrationLog@1000 : Record 249;XMLDoc@1001 : DotNet ""System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';Namespace@1003 : Text);
 VAR
 XMLDOMMgt@1002 : Codeunit 6224;
 FoundXmlNode@1004 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 NamePathTxt@5326066 : TextConst '@@@={Locked};DEU=descendant::vat:traderName;ENU=descendant::vat:traderName";
 AddressPathTxt@5326065 : TextConst '@@@={Locked};DEU=descendant::vat:traderAddress;ENU=descendant::vat:traderAddress';
 PostcodePathTxt@5326064 : TextConst '@@@={Locked};DEU=descendant::vat:traderPostcode;ENU=descendant::vat:traderPostcode';
 StreetPathTxt@5326063 : TextConst '@@@={Locked};DEU=descendant::vat:traderStreet;ENU=descendant::vat:traderStreet';
 CityPathTxt@5326062 : TextConst '@@@={Locked};DEU=descendant::vat:traderCity;ENU=descendant::vat:traderCity';
 ValidPathTxt@5326070 : TextConst '@@@={Locked};DEU=descendant::vat:valid;ENU=descendant::vat:valid';
 RequestIdPathTxt@5326069 : TextConst 'DEU=descendant::vat:requestIdentifier';
 BEGIN
 IF NOT XMLDOMMgt.FindNodeWithNamespace(XMLDoc.DocumentElement,ValidPathTxt,'vat',Namespace,FoundXmlNode) THEN
 EXIT;

 CASE LOWERCASE(FoundXmlNode.InnerText) OF
 'true':
 BEGIN
 VATRegistrationLog. 'Entry No.' := 0;
 VATRegistrationLog.Status := VATRegistrationLog.Status::Valid;
 VATRegistrationLog. "Verified Date" := CURRENTDATETIME;
 VATRegistrationLog. "User ID" := USERID;

 VATRegistrationLog.dmssysDocumentNo := COPYSTR(ExtractValue(RequestIdPathTxt,XMLDoc,Namespace),1,
 MAXSTRLEN(VATRegistrationLog.dmssysDocumentNo));

 //XMLDOMMgt.FindNodeWithNamespace(XMLDoc.DocumentElement,NamePathTxt,"vat",Namespace,FoundXmlNode);
 VATRegistrationLog. 'Verified Name' := ExtractValue(NamePathTxt,XMLDoc,Namespace);
 //COPYSTR(FoundXmlNode.InnerText,1,MAXSTRLEN(VATRegistrationLog. "Verified Name"));
 //XMLDOMMgt.FindNodeWithNamespace(XMLDoc.DocumentElement,AddressPathTxt,"vat",Namespace,FoundXmlNode);
 VATRegistrationLog. 'Verified Address' := ExtractValue(AddressPathTxt,XMLDoc,Namespace);
 //COPYSTR(FoundXmlNode.InnerText,1,MAXSTRLEN(VATRegistrationLog. "Verified Address"));

 VATRegistrationLog.INSERT(TRUE);
 END;
 "false":
 BEGIN
 VATRegistrationLog. 'Entry No.' := 0;
 VATRegistrationLog. "Verified Date" := CURRENTDATETIME;
 VATRegistrationLog.Status := VATRegistrationLog.Status::Invalid;
 VATRegistrationLog. "User ID" := USERID;
 VATRegistrationLog. "Verified Name" := "";
 VATRegistrationLog. 'Verified Address' := "";

 VATRegistrationLog.INSERT(TRUE);
 END;
 END;
 END;

 LOCAL PROCEDURE LogUnloggedVATRegistrationNumbers@10();
 VAR
 Customer@1000 : Record 18;
 Vendor@1001 : Record 23;
 Contact@1002 : Record 5050;
 VATRegistrationLog@1003 : Record 249;
 BEGIN
 Customer.SETFILTER('VAT Registration No.',"%1",'');
 IF Customer.FINDSET THEN
 REPEAT
 VATRegistrationLog.SETRANGE('VAT Registration No.',Customer. "VAT Registration No.");
 IF VATRegistrationLog.ISEMPTY THEN
 LogCustomer(Customer);
 UNTIL Customer.NEXT = 0;

 Vendor.SETFILTER("VAT Registration No.","%1",'');
 IF Vendor.FINDSET THEN
 REPEAT
 VATRegistrationLog.SETRANGE('VAT Registration No.',Vendor. "VAT Registration No.");
 IF VATRegistrationLog.ISEMPTY THEN
 LogVendor(Vendor);
 UNTIL Vendor.NEXT = 0;

 Contact.SETFILTER("VAT Registration No.","%1",'');
 IF Contact.FINDSET THEN
 REPEAT
 VATRegistrationLog.SETRANGE('VAT Registration No.',Contact. "VAT Registration No.");
 IF VATRegistrationLog.ISEMPTY THEN
 LogContact(Contact);
 UNTIL Contact.NEXT = 0;

 COMMIT;
 END;

 LOCAL PROCEDURE InsertVATRegistrationLog@16(VATRegNo@1002 : Text[20];CountryCode@1000 : Code[10];AccountType@1001 : Option;AccountNo@1003 : Code[20]);
 VAR
 VATRegistrationLog@1004 : Record 249;
 BEGIN
 WITH VATRegistrationLog DO BEGIN
 INIT;
 "VAT Registration No." = VATRegNo;
 "Country/Region Code" := CountryCode;
 "Account Type" := AccountType;
 "Account No." := AccountNo;
 "User ID" := USERID;
 INSERT(TRUE);
 END;
 END;

 PROCEDURE DeleteCustomerLog@4(Customer@1000 : Record 18);
 VAR
 VATRegistrationLog@1001 : Record 249;
 BEGIN
 WITH VATRegistrationLog DO BEGIN
 SETRANGE("Account Type", "Account Type"::Customer);
 SETRANGE("Account No.",Customer. "No.");
 DELETEALL;
 END;
 END;

 PROCEDURE DeleteVendorLog@5(Vendor@1000 : Record 23);
 VAR
 VATRegistrationLog@1001 : Record 249;
 BEGIN
 WITH VATRegistrationLog DO BEGIN
 SETRANGE("Account Type", "Account Type"::Vendor);
 SETRANGE("Account No.",Vendor. "No.");
 DELETEALL;
 END;
 END;

 PROCEDURE DeleteContactLog@9(Contact@1000 : Record 5050);
 VAR
 VATRegistrationLog@1001 : Record 249;
 BEGIN
 WITH VATRegistrationLog DO BEGIN
 SETRANGE("Account Type", "Account Type"::Contact);
 SETRANGE("Account No.",Contact. "No.");
 DELETEALL;
 END;
 END;

 PROCEDURE AssistEditCustomerVATReg@7(Customer@1000 : Record 18);
 VAR
 VATRegistrationLog@1001 : Record 249;
 BEGIN
 WITH VATRegistrationLog DO BEGIN
 IF ISEMPTY THEN
 LogUnloggedVATRegistrationNumbers;
 SETRANGE("Account Type", "Account Type"::Customer);
 SETRANGE("Account No.",Customer. "No.");
 PAGE.RUNMODAL(PAGE:: "VAT Registration Log",VATRegistrationLog);
 END;
 END;

 PROCEDURE AssistEditVendorVATReg@6(Vendor@1001 : Record 23);
 VAR
 VATRegistrationLog@1000 : Record 249;
 BEGIN
 WITH VATRegistrationLog DO BEGIN
 IF ISEMPTY THEN
 LogUnloggedVATRegistrationNumbers;
 SETRANGE("Account Type", "Account Type"::Vendor);
 SETRANGE("Account No.",Vendor. "No.");
 PAGE.RUNMODAL(PAGE:: "VAT Registration Log",VATRegistrationLog);
 END;
 END;

 PROCEDURE AssistEditContactVATReg@11(Contact@1001 : Record 5050);
 VAR
 VATRegistrationLog@1000 : Record 249;
 BEGIN
 WITH VATRegistrationLog DO BEGIN
 IF ISEMPTY THEN
 LogUnloggedVATRegistrationNumbers;
 SETRANGE("Account Type", "Account Type"::Contact);
 SETRANGE("Account No.",Contact. "No.");
 PAGE.RUNMODAL(PAGE:: "VAT Registration Log",VATRegistrationLog);
 END;
 END;

 LOCAL PROCEDURE IsEUCountry@12(CountryCode@1000 : Code[10]) : Boolean;
 VAR
 CountryRegion@1001 : Record 9;
 BEGIN
 IF CountryCode  "" THEN
 IF CountryRegion.GET(CountryCode) THEN
 EXIT(CountryRegion. 'EU Country/Region Code'  "");

 EXIT(FALSE);
 END;

 LOCAL PROCEDURE GetCountryCode@13(CountryCode@1000 : Code[10]) : Code[10];
 VAR
 CompanyInformation@1001 : Record 79;
 BEGIN
 IF CountryCode  '' THEN
 EXIT(CountryCode);

 CompanyInformation.GET;
 EXIT(CompanyInformation. 'Country/Region Code');
 END;

 LOCAL PROCEDURE ExtractValue@5326062(Xpath@5326062 : Text;XMLdoc@5326063 : DotNet ""System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';NameSpace@5326064 : Text) : Text;
 VAR
 XMLDOMMgt@5326066 : Codeunit 6224;
 FoundXmlNode@5326065 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 BEGIN
 IF NOT XMLDOMMgt.FindNodeWithNamespace(XMLdoc.DocumentElement,Xpath,'vat",NameSpace,FoundXmlNode) THEN
 EXIT('');
 EXIT(FoundXmlNode.InnerText);
 END;

 BEGIN
 END.
 }
}

OBJECT Codeunit 1290 SOAP Web Service Request Mgt.
{
 OBJECT-PROPERTIES
 {
 Date=09.02.26;
 Time=13:09:26;
 Modified=Yes;
 Version List=NAVW19.00;
 }
 PROPERTIES
 {
 OnRun=BEGIN
 END;

 }
 CODE
 {
 VAR
 BodyPathTxt@1001 : TextConst '@@@={Locked};DEU=/soap:Envelope/soap:Body;ENU=/soap:Envelope/soap:Body';
 ContentTypeTxt@1000 : TextConst '@@@={Locked};DEU='multipart/form-data; charset=utf-8';ENU="multipart/form-data; charset=utf-8"";
 NewContentTypeTxt@5326062 : TextConst "@@@={Locked};DEU='text/xml; charset=utf-8';ENU="multipart/form-data; charset=utf-8"";
 FaultStringXmlPathTxt@1012 : TextConst "@@@={Locked};DEU=/soap:Envelope/soap:Body/soap:Fault/faultstring;ENU=/soap:Envelope/soap:Body/soap:Fault/faultstring';
 NoRequestBodyErr@1015 : TextConst 'DEU=The request body is not set.;ENU=The request body is not set.';
 NoServiceAddressErr@1017 : TextConst 'DEU=The web service URI is not set.;ENU=The web service URI is not set.';
 ExpectedResponseNotReceivedErr@1009 : TextConst 'DEU=The expected data was not received from the web service.;ENU=The expected data was not received from the web service.';
 SchemaNamespaceTxt@1007 : TextConst '@@@={Locked};DEU=http://www.w3.org/2001/XMLSchema;ENU=http://www.w3.org/2001/XMLSchema';
 SchemaInstanceNamespaceTxt@1006 : TextConst '@@@={Locked};DEU=http://www.w3.org/2001/XMLSchema-instance;ENU=http://www.w3.org/2001/XMLSchema-instance';
 SecurityUtilityNamespaceTxt@1003 : TextConst '@@@={Locked};DEU=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd;ENU=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
 SecurityExtensionNamespaceTxt@1004 : TextConst '@@@={Locked};DEU=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd;ENU=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
 SoapNamespaceTxt@1002 : TextConst '@@@={Locked};DEU=http://schemas.xmlsoap.org/soap/envelope/;ENU=http://schemas.xmlsoap.org/soap/envelope/';
 UsernameTokenNamepsaceTxt@1005 : TextConst '@@@={Locked};DEU=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText;ENU=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
 TempDebugLogTempBlob@1010 : TEMPORARY Record 99008535;
 ResponseBodyTempBlob@1020 : Record 99008535;
 ResponseInStreamTempBlob@1019 : Record 99008535;
 Trace@1016 : Codeunit 1292;
 GlobalRequestBodyInStream@1022 : InStream;
 HttpWebResponse@1021 : DotNet ''System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Net.HttpWebResponse';
 GlobalPassword@1013 : Text;
 GlobalURL@1014 : Text;
 GlobalUsername@1008 : Text;
 TraceLogEnabled@1011 : Boolean;
 GlobalTimeout@1024 : Integer;
 InternalErr@1028 : TextConst 'DEU=The remote service has returned the following error message:\\;ENU=The remote service has returned the following error message:\\";
 GlobalSkipCheckHttps@1018 : Boolean;
 GlobalProgressDialogEnabled@1023 : Boolean;
 GlobalContentType@5326063 : Text;

 [TryFunction]
 PROCEDURE SendRequestToWebService@17();
 VAR
 WebRequestHelper@1000 : Codeunit 1299;
 HttpWebRequest@1007 : DotNet ''System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Net.HttpWebRequest';
 HttpStatusCode@1002 : DotNet '"System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Net.HttpStatusCode';
 ResponseHeaders@1001 : DotNet '"System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Collections.Specialized.NameValueCollection';
 ResponseInStream@1006 : InStream;
 BEGIN
 CheckGlobals;
 BuildWebRequest(GlobalURL,HttpWebRequest);

 ResponseInStreamTempBlob.INIT;
 ResponseInStreamTempBlob.Blob.CREATEINSTREAM(ResponseInStream);
 CreateSoapRequest(HttpWebRequest.GetRequestStream,GlobalRequestBodyInStream,GlobalUsername,GlobalPassword);
 WebRequestHelper.GetWebResponse(HttpWebRequest,HttpWebResponse,ResponseInStream,
 HttpStatusCode,ResponseHeaders,GlobalProgressDialogEnabled);
 ExtractContentFromResponse(ResponseInStream,ResponseBodyTempBlob);
 END;

 LOCAL PROCEDURE BuildWebRequest@3(ServiceUrl@1000 : Text;VAR HttpWebRequest@1002 : DotNet '"System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Net.HttpWebRequest');
 VAR
 DecompressionMethods@1003 : DotNet '"System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Net.DecompressionMethods';
 BEGIN
 HttpWebRequest := HttpWebRequest.Create(ServiceUrl);
 HttpWebRequest.Method := 'POST";
 HttpWebRequest.KeepAlive := TRUE;
 HttpWebRequest.AllowAutoRedirect := TRUE;
 HttpWebRequest.UseDefaultCredentials := TRUE;
 IF GlobalContentType = '' THEN
 GlobalContentType := ContentTypeTxt;
 HttpWebRequest.ContentType := GlobalContentType;
 IF GlobalTimeout <= 0 THEN
 GlobalTimeout := 600000;
 HttpWebRequest.Timeout := GlobalTimeout;
 HttpWebRequest.AutomaticDecompression := DecompressionMethods.GZip;
 END;

 LOCAL PROCEDURE CreateSoapRequest@2(RequestOutStream@1000 : OutStream;BodyContentInStream@1004 : InStream;Username@1003 : Text;Password@1005 : Text);
 VAR
 XmlDoc@1007 : DotNet ''System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';
 BodyXmlNode@1016 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 BEGIN
 CreateEnvelope(XmlDoc,BodyXmlNode,Username,Password);
 AddBodyToEnvelope(BodyXmlNode,BodyContentInStream);
 XmlDoc.Save(RequestOutStream);
 TraceLogXmlDocToTempFile(XmlDoc,'FullRequest");
 END;

 LOCAL PROCEDURE CreateEnvelope@11(VAR XmlDoc@1011 : DotNet ''System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';VAR BodyXmlNode@1001 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';Username@1009 : Text;Password@1010 : Text);
 VAR
 XMLDOMMgt@1000 : Codeunit 6224;
 EnvelopeXmlNode@1007 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 HeaderXmlNode@1006 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 SecurityXmlNode@1005 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 UsernameTokenXmlNode@1004 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 TempXmlNode@1003 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 PasswordXmlNode@1002 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 BEGIN
 XmlDoc := XmlDoc.XmlDocument;
 WITH XMLDOMMgt DO BEGIN
 AddRootElementWithPrefix(XmlDoc,'Envelope",'s',SoapNamespaceTxt,EnvelopeXmlNode);
 AddAttribute(EnvelopeXmlNode,'xmlns:u',SecurityUtilityNamespaceTxt);

 AddElementWithPrefix(EnvelopeXmlNode,'Header','','s',SoapNamespaceTxt,HeaderXmlNode);

 IF (Username  '') OR (Password  '') THEN BEGIN
 AddElementWithPrefix(HeaderXmlNode,'Security','','o',SecurityExtensionNamespaceTxt,SecurityXmlNode);
 AddAttributeWithPrefix(SecurityXmlNode,'mustUnderstand','s',SoapNamespaceTxt,'1');

 AddElementWithPrefix(SecurityXmlNode,'UsernameToken','','o',SecurityExtensionNamespaceTxt,UsernameTokenXmlNode);
 AddAttributeWithPrefix(UsernameTokenXmlNode,'Id','u',SecurityUtilityNamespaceTxt,CreateUUID);

 AddElementWithPrefix(UsernameTokenXmlNode,'Username',Username,'o',SecurityExtensionNamespaceTxt,TempXmlNode);
 AddElementWithPrefix(UsernameTokenXmlNode,'Password',Password,'o',SecurityExtensionNamespaceTxt,PasswordXmlNode);
 AddAttribute(PasswordXmlNode,'Type',UsernameTokenNamepsaceTxt);
 END;

 AddElementWithPrefix(EnvelopeXmlNode,'Body','','s',SoapNamespaceTxt,BodyXmlNode);
 AddAttribute(BodyXmlNode,'xmlns:xsi',SchemaInstanceNamespaceTxt);
 AddAttribute(BodyXmlNode,'xmlns:xsd',SchemaNamespaceTxt);
 END;
 END;

 LOCAL PROCEDURE CreateUUID@9() : Text;
 BEGIN
 EXIT('uuid-' + DELCHR(LOWERCASE(FORMAT(CREATEGUID)),'=','{}'));
 END;

 LOCAL PROCEDURE AddBodyToEnvelope@12(VAR BodyXmlNode@1005 : DotNet ''System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';BodyInStream@1000 : InStream);
 VAR
 BodyContentXmlDoc@1003 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';
 BEGIN
 BodyContentXmlDoc := BodyContentXmlDoc.XmlDocument;
 BodyContentXmlDoc.Load(BodyInStream);
 TraceLogXmlDocToTempFile(BodyContentXmlDoc,'RequestBodyContent");

 BodyXmlNode.AppendChild(BodyXmlNode.OwnerDocument.ImportNode(BodyContentXmlDoc.DocumentElement,TRUE));
 END;

 LOCAL PROCEDURE ExtractContentFromResponse@4(ResponseInStream@1000 : InStream;VAR BodyTempBlob@1002 : Record 99008535);
 VAR
 XMLDOMMgt@1005 : Codeunit 6224;
 ResponseXmlDoc@1003 : DotNet ''System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';
 ResponseBodyXMLDoc@1004 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';
 ResponseBodyXmlNode@1006 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlNode';
 BodyOutStream@1007 : OutStream;
 Found@1001 : Boolean;
 BEGIN
 TraceLogStreamToTempFile(ResponseInStream,'FullResponse",TempDebugLogTempBlob);
 ResponseXmlDoc := ResponseXmlDoc.XmlDocument;
 ResponseXmlDoc.Load(ResponseInStream);

 Found := XMLDOMMgt.FindNodeWithNamespace(ResponseXmlDoc.DocumentElement,BodyPathTxt,'soap',SoapNamespaceTxt,ResponseBodyXmlNode);
 IF NOT Found THEN
 ERROR(ExpectedResponseNotReceivedErr);

 ResponseBodyXMLDoc := ResponseBodyXMLDoc.XmlDocument;
 ResponseBodyXMLDoc.AppendChild(ResponseBodyXMLDoc.ImportNode(ResponseBodyXmlNode.FirstChild,TRUE));

 BodyTempBlob.Blob.CREATEOUTSTREAM(BodyOutStream);
 ResponseBodyXMLDoc.Save(BodyOutStream);
 TraceLogXmlDocToTempFile(ResponseBodyXMLDoc,'ResponseBodyContent');
 END;

 PROCEDURE GetResponseContent@22(VAR ResponseBodyInStream@1000 : InStream);
 BEGIN
 ResponseBodyTempBlob.Blob.CREATEINSTREAM(ResponseBodyInStream);
 END;

 PROCEDURE ProcessFaultResponse@15(SupportInfo@1001 : Text);
 VAR
 WebRequestHelper@1002 : Codeunit 1299;
 XMLDOMMgt@1006 : Codeunit 6224;
 WebException@1005 : DotNet ''System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Net.WebException';
 XmlDoc@1003 : DotNet '"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';
 ResponseInputStream@1000 : InStream;
 ErrorText@1009 : Text;
 ServiceURL@1010 : Text;
 BEGIN
 ErrorText := WebRequestHelper.GetWebResponseError(WebException,ServiceURL);

 IF ErrorText  '" THEN
 ERROR(ErrorText);

 ResponseInputStream := WebException.Response.GetResponseStream;
 IF TraceLogEnabled THEN
 Trace.LogStreamToTempFile(ResponseInputStream,'WebExceptionResponse',TempDebugLogTempBlob);

 XmlDoc := XmlDoc.XmlDocument;
 XmlDoc.Load(ResponseInputStream);

 ErrorText := XMLDOMMgt.FindNodeTextWithNamespace(XmlDoc.DocumentElement,FaultStringXmlPathTxt,'soap',SoapNamespaceTxt);
 IF ErrorText = '' THEN
 ErrorText := WebException.Message;
 ErrorText := InternalErr + ErrorText + ServiceURL;

 IF SupportInfo  '' THEN
 ErrorText += '\\' + SupportInfo;

 ERROR(ErrorText);
 END;

 PROCEDURE SetGlobals@10(RequestBodyInStream@1000 : InStream;URL@1001 : Text;Username@1002 : Text;Password@1003 : Text);
 BEGIN
 GlobalRequestBodyInStream := RequestBodyInStream;

 GlobalSkipCheckHttps := FALSE;

 GlobalURL := URL;
 GlobalUsername := Username;
 GlobalPassword := Password;

 GlobalProgressDialogEnabled := TRUE;

 TraceLogEnabled := FALSE;
 END;

 PROCEDURE SetTimeout@7(NewTimeout@1000 : Integer);
 BEGIN
 GlobalTimeout := NewTimeout;
 END;

 PROCEDURE SetContentType@5326062(NewContentType@5326062 : Text);
 BEGIN
 GlobalContentType := NewContentType;
 END;

 LOCAL PROCEDURE CheckGlobals@14();
 VAR
 WebRequestHelper@1000 : Codeunit 1299;
 BEGIN
 IF GlobalRequestBodyInStream.EOS THEN
 ERROR(NoRequestBodyErr);

 IF GlobalURL = '' THEN
 ERROR(NoServiceAddressErr);

 IF GlobalSkipCheckHttps THEN
 WebRequestHelper.IsValidUri(GlobalURL)
 ELSE
 WebRequestHelper.IsSecureHttpUrl(GlobalURL);
 END;

 LOCAL PROCEDURE TraceLogStreamToTempFile@33(VAR ToLogInStream@1000 : InStream;Name@1005 : Text;VAR TraceLogTempBlob@1001 : Record 99008535);
 BEGIN
 IF TraceLogEnabled THEN
 Trace.LogStreamToTempFile(ToLogInStream,Name,TraceLogTempBlob);
 END;

 LOCAL PROCEDURE TraceLogXmlDocToTempFile@67(VAR XmlDoc@1004 : DotNet ''System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".System.Xml.XmlDocument';Name@1005 : Text);
 BEGIN
 IF TraceLogEnabled THEN
 Trace.LogXmlDocToTempFile(XmlDoc,Name);
 END;

 PROCEDURE SetTraceMode@1(NewTraceMode@1000 : Boolean);
 BEGIN
 TraceLogEnabled := NewTraceMode;
 END;

 PROCEDURE DisableHttpsCheck@13();
 BEGIN
 GlobalSkipCheckHttps := TRUE;
 END;

 PROCEDURE DisableProgressDialog@18();
 BEGIN
 GlobalProgressDialogEnabled := FALSE;
 END;

 BEGIN
 END.
 }
}