Purpose Use a web service to facilitate data entry |
Solution In this example we use the Google Geo API to determine the city for a given postal code and country. We add a small button in the SAP address entry screen which determines the name of the city via the web service and fills in the SAP GUI "City" field:
"@0D\QCity from postal code@" _ size=(1,1) _ process="city_from_postal_code.txt" InputScript "city_from_postal_code.txt" // determine city via
JavaScript / Google web api "&F[ADDR1_DATA-POST_CODE1]" _ "&F[ADDR1_DATA-COUNTRY]" // Set city Set F[ADDR1_DATA-CITY1] "&V[city]" Return else Return "E: No city found for this postal code" -statusline endif JavaScript function // read city from postal code via Google service function city_from_postal_code(postal_code, country_code) { var city = ""; var xmlDoc = guixt.CreateObject("Microsoft.XMLDOM"); if (!xmlDoc) { alert("Web Service for city name failed: " + "Microsoft XML parser not loadable"); return city; }; var APIkey = "BIzaSyDKFrg0q2fAoybONfNOWL-7i8iUpcj9tOE"; var url = "https://maps.googleapis.com/maps/api/geocode/xml?address=" + postal_code + "," + country_code + "&key=" + APIkey; xmlDoc.async = "false"; xmlDoc.load(url); var XPath = "/GeocodeResponse/result" + "/address_component[type='locality']/long_name"; var nodes = xmlDoc.selectNodes(XPath); if (nodes.length > 0) { city = nodes[0].text; }; xmlDoc = null; return city; }; |
Components |