/** Insert the following in the head tags
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
**/
var dataFromGoogleSheetsAsArray= '';
var dataFromGoogleSheets='';
/** googleSheetsCode - refers to the Deployment Web APP URL, when a google 'App Script' is deployed. This code looks like this: 'https://script.google.com/macros/s/AKfycbybmKK8zur1QdwnceC57SvqUtG1LTTey9MbP2tFBeT_tiom2K-_ABox6EMaE9scmIn4pw/exec';
arrayToSendToGoogleSheets - the first entry must be the name of the function to call in the Google App Script to be called. All the other entries are data that may be processed by the function, once in the App Script.
**/
function sendDataToGoogleSheets(arrayToSendToGoogleSheets,googleSheetsCode) {
var arrayAsStringToSendToGoogleSheets= arrayToSendToGoogleSheets.join('*^^*');
jQuery.post(googleSheetsCode, {
arrayAsString: arrayAsStringToSendToGoogleSheets
}).done(function (data) {
dataFromGoogleSheets=data;
dataFromGoogleSheetsAsArray=data.split('*^^*');
receiveDataFromGoogleSheets();
})
}
//function receiveDataToGoogleSheets
/**To get data the processed data from googlesheets, use the following code in the webpage.
Note: the first entry of the array is the name of the function to call in the webpage, all
other entries are data that may be used in the webpage.
function receiveDataFromGoogleSheets(){
if(getDataFromGoogleSheetsAsArray()[0]=='functionToCallInTheWebpage'){}
}
**/
function getDataFromGoogleSheetsAsArray(){
return dataFromGoogleSheetsAsArray;}
function getDataFromGoogleSheets(){
return dataFromGoogleSheets;}
/**
var textToReturn='';
var tempArray=[];
//To return data to googlesheetportal
//tempArray must be converted to a string and saved in textToReturn.
//the first entry of the tempArray must be the name of the function to call in the webpage.
textToReturn=tempArray.join('*^^*');
function doPost(e){
var arrayAsString=e.parameter.arrayAsString;
var array=arrayAsString.split('*^^*');
processArray(array);
return ContentService.createTextOutput(textToReturn);
}
function processArray(arrayToProcess){
//example of calling function
//if(arrayToProcess[0]=='nameOfFunctionToCall'){
// nameOfFunctionToCall(arrayToProcess);
//}
}
//function nameOfFunctionToCall(dataToProcess){
//tempArray[0]='functionToCallInTheWebpage';
//textToReturn=tempArray.join('*^^*');
//}
**/