Create a European VAT ID checker (also works for Zoho CRM!)
For invoicing to other businesses within the EU, it is mandatory to check whether the VAT ID of your customer is correct, in order to invoice using a 0% tax rate. I wrote a script that checks the VAT number that you have from your customer against
the EU database of VAT IDs. The easiest way to use this script is to put it in a function and call that function from a workflow or button.
The function is as follows:
- String checkVAT(String vat_id)
- {
- if(vat_id == "" || vat_id == null)
- {
- return "Enter number in VAT first!";
- }
- else
- {
- vat_id = getAlphaNumeric(vat_id);
- countryCode = vat_id.subString(0,2);
- vatNumber = vat_id.remove(countryCode);
- url = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService";
- //Uncomment next three lines for testing
- // countryCode = "NL";
- // vatNumber = "200";
- // url = "http://ec.europa.eu/taxation_customs/vies/services/checkVatTestService";
- request = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"> <Body> <checkVat xmlns=\"urn:ec.europa.eu:taxud:vies:services:checkVat:types\">";
- request = request + "<countryCode>" + countryCode + "</countryCode>";
- request = request + " <vatNumber>" + vatNumber + "</vatNumber>";
- request = request + " </checkVat> </Body></Envelope>";
- headers = Map();
- headers.put("Content-Type","text/xml");
- vat_data = invokeurl
- [
- url :url
- type :POST
- parameters:request
- headers:headers
- ];
- validity = vat_data.getsuffix("valid>");
- validity = validity.getprefix("</");
- if(validity == "true")
- {
- validity = "valid";
- }
- else
- {
- validity = "INVALID";
- }
- name = vat_data.getsuffix("name>");
- name = name.getprefix("</");
- address = vat_data.getsuffix("address>");
- address = address.getprefix("</");
- return "The VAT number is " + validity + if(validity=="valid",". The registered name is " + name + " and the registered address is " + address + ".","");
- }
- }
Here's what the script does:
- It uses the VAT number that was included as parameter vat_id. This can be gathered for instance from a field in your form.
- It returns a string: this is either
- a message that the VAT number was not filled in (first IF statement)
- a message that the number is invalid (row 41)
- a message that the number is valid, including the registered name and address (the IF statement in row 41)
- The service needs the country code and VAT number separately. This is extracted in rows 9-11.
- The request to the service is prepared (row 12-20) and sent (row 21-26). If you want to test without an actual number, uncomment lines 14-16: it will use the test service.
- The returned message is checked for validity of the number (row 27-28) and the name and address are extracted (rows 37-40)
You can extend this script in whichever way you like. For instance, you could write a script that checks whether the name and address match with what is filled in.
Related Articles
Add a custom logo to an app
Zoho Creator gives you a couple of options for the logo that is displayed in the top left corner of an app: Your company logo (the same for all your apps) An icon from the predefined icon list A 1-3 letter combination Now, you might have different ...
Sending images to imagekit.io using API
imagekit.io is a service for optimising media content for websites. It's API is pretty straightforward, but it's always a bit finicky to get a connection going the way you want it. To make an API call, first follow the steps in "Authorisation" and ...
Creating a Function
When you have a piece of scripting code that you use frequently, it can be better to create a function for this. Instead of copying this piece of code (and having to update each and every instance when you need to change it!), you have it in one ...
Limitations in CSS styling
Styling forms in Zoho Creator using CSS styling in a Notes field brings many possibilities, but unfortunately not all CSS properties and functions work: some are simply stripped out. Whenever I come across a limitation, I add it to the list below, ...