My current task involves parsing an XML document tree upon clicking a button. The XML file is obtained using a lookup function that requires two values ("id" and "shipping") to be inserted into the appropriate URL. Then, the data retrieved is parsed using JSON.parse and added to the "address" text field. Now, I am faced with the challenge of dynamically populating another input line with the results of this parse. Unfortunately, the URLFetch function is only accessible on the code.gs side. Is there a way to transfer the array from the gs side to my JavaScript side, or should I resort to using an XMLHttpRequest function?
I have experimented with performing the URL fetch on the JavaScript side and even tried implementing a new function called "httpGet".
URLFetch Function:
document.getElementById('lookup').addEventListener('click',personLookup);
function personLookup(){
var patient = document.getElementById('id').value;
var shippingStyle = document.getElementById('shipping').value;
var address = document.getElementById('address');
var url = "someurl?patientID=" + patient;
var shippingAddress = UrlFetchApp.fetch(url,{'muteHttpExceptions':true});
Console.log(shippingAddress)
var addressData = JSON.parse(shippingAddress.getContentText());
var shipAdd = addressData.Address;
var city = addressData.City;
var state = addressData.State;
var zip = addressData.Zip;
address.value = shipAdd + "," + city + "," + state + "," + zip;
};
HttpGet function:
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous
request
xmlHttp.send( null );
return xmlHttp.responseText;
}
Despite realizing that URLFetch is restricted to the gs side and encountering issues with the httpGet function not meeting my requirements, I am also less familiar with this approach compared to the fetch function.