Google-apps-script – What works with the new Apps Script runtime powered by Chrome V8 for this project

google-apps-script

Post edited to clarify:

I found the following code that allows me to query my 3dCart store database and dump the information into a sheet. I tried upgrading to the new Apps Script runtime powered by Chrome V8 and it fails. I get the following error:

ReferenceError: Xml is not defined (line 12, file "Utilities")

var api_key = "";
var store_url = "";
// These settings can be hardcoded or placed in the "SETTINGS" sheet

function queryCart(strSql) {
  // This script relies on the SoapService which was deprecated beginning 7/2013 and will be unavailable 2/2014!

  loadSettingsFromSheet();
  var wsdl = SoapService.wsdl("http://api.3dcart.com/cart_advanced.asmx?WSDL");
  var cartAPI = wsdl.getService("cartAPIAdvanced");

  var param = Xml.element("runQuery", [
                Xml.attribute("xmlns", "http://3dcart.com/"),
                Xml.element("storeUrl", [store_url]),
                Xml.element("userKey", [api_key]),
                Xml.element("callBackURL", [""]),
                Xml.element("sqlStatement", [strSql])
              ]);


//  var envelope = cartAPI.getSoapEnvelope("runQuery", param); // Use to examine request without sending

  var result_full = cartAPI.invokeOperation("runQuery", [param]);
  var result = result_full.Envelope.Body.runQueryResponse.runQueryResult;

  return result;
}

apps script screenshot from script editor with information

Best Answer

The major problem with the code that you found is that it's using a service that "will be retired" in 2014 and we are in 2020.


I had a very similar problem the last week regarding the Xml Service. What I did was to revert my project to use Rhino instead of Chrome V8,

The above because there isn't another Google Apps Script built-in service that works as the Xml Service. The "closest" is the XmlService Service

In my case, I was using it for for HTML parsing but the workarounds/solutions are too complex for the needs of my project.

One workaround for HTML parsing is to use string handling techniques like using regular expressions which is not an easy task because HTML cannot always be parsed effectively by using them, actually some people discourages this.

The pro way to go is to use a HTML parsing code library. You could ask for a software recommendation in https://softwarerecs.stackexchange.com and/or search for questions about HTML parsing using Google Apps Script / JavaScript in https://stackoverflow.com.

Related

References