Get VAT registration number for Customer, Vendor and Legal entity X++
Hi D365 FO Tech Guys,
Greetings!
In this post, i am going to share X++ code snippets of how you can get VAT number for Customer, Vendor and Legal entity. This requirement is very common in those countries where VAT regulations are imposed and VAT number is mandatory to be displayed on external document prints like Sales invoice, Purchase order etc.
Since, there is a possibility of multiple VAT registration number versions for the same vendor, customer or legal entity and one version is active that's why ValidTo condition in the X++ query is required to handle multiple VAT registration number versions and capture active VAT registration number version
Customer VAT:
select custTable
where custTable.AccountNum == "CUST00001"
join dirpartytableCust
where dirpartytableCust.RecId==custTable.Party
join dirpartylocationCust
where dirpartylocationCust.Party==dirpartytableCust.RecId && dirpartylocationCust.IsPrimary==1
join RegistrationNumber from taxregistrationCust
where taxregistrationCust.DirPartyLocation == dirPartyLocationCust.RecId && taxregistrationCust.ValidTo>=today();
info(strfmt("Customer VAT: %1", taxregistrationCust.RegistrationNumber));
Vendor VAT:
select vendTable
where vendTable.AccountNum == "VEND00001"
join dirpartytableVend
where dirpartytableVend.RecId==vendTable.Party
join dirpartylocationVend
where dirpartylocationVend.Party==dirpartytableVend.RecId && dirpartylocationVend.IsPrimary==1
join RegistrationNumber from taxregistrationVend
where taxregistrationVend.DirPartyLocation == dirPartyLocationVend.RecId && taxregistrationVend.ValidTo>=today();
info(strfmt("Vendor VAT: %1", taxregistrationVend.RegistrationNumber));
Legal entity VAT:
select _companyInfo
where _companyInfo.DataArea ==curExt()
join dirpartytable
where dirpartytable.PartyNumber ==_companyInfo.PartyNumber
join dirpartylocation
where dirpartylocation.Party == dirpartytable.RecId && dirpartylocation.IsPrimary==1
join RegistrationNumber from taxregistration
where taxregistration.DirPartyLocation == dirPartyLocation.RecId && taxregistration.ValidTo>=today();
info(strfmt("Company VAT: %1", taxregistration.RegistrationNumber));

Like
Report
*This post is locked for comments