VAT ID Check using XML-RPC

Hi Thomas,

In the beginning, the workflow didn’t work as intended. But I eventually found the 2 issues:

  1. The RPC only works using GET, not POST.
  2. The response seemed to be contained in a data string like this:
    " UstId_1 ErrorCode 215 UstId_2 Druck nein Erg_PLZ Ort Datum 08.08.2024 PLZ Erg_Ort Uhrzeit 11:48:39 Erg_Name Gueltig_ab Gueltig_bis Strasse Firmenname Erg_Str "

I first tried extracting the ErrorCode using a JS string function but this never worked (result always null).
Actually, the result string is an XML structure like the one from above:
image

I then asked Gemini once again and it suggested a specific XML script:

function extractErrorCode(xmlString) {
// Create a DOMParser instance
const parser = new DOMParser();

// Parse the XML string into a DOM document
const xmlDoc = parser.parseFromString(xmlString, “text/xml”);

// Get all elements
const params = xmlDoc.getElementsByTagName(“param”);

// Iterate over params to find the one with key “ErrorCode”
for (let i = 0; i < params.length; i++) {
const keyElement = params[i].getElementsByTagName(“string”)[0];
if (keyElement.textContent === “ErrorCode”) {
const valueElement = params[i].getElementsByTagName(“string”)[1];
return valueElement.textContent;
}
}

return null; // Handle case where ErrorCode not found
}

const xmlString = context.workflow[‘3bdd1ccc-f5c6-457a-8ac7-872566f61929’].result?.[‘data’]/* your XML string here */;
const errorCode = extractErrorCode(xmlString);
// console.log(errorCode); // Output: 200 >> valid
return(errorCode);

This works perfectly! I now added a workflow True/False split using the returned ErrorCode: 200 = valid (true), other codes: error message