Hello TimAI2,
Can you give me more detail on how to use your script to read and write to a google sheet ?
I can’t find anywhere how to call a google apps script web app bound to the spreadsheet from app inventor.
Here is your Google Apps Script Webb App code plus some other code I found here :
function doGet(e) {
return ReadOrWrite(e);
}
function ReadOrWrite(e){
// Read from A1 to A6
if(e.parameter.func == "READ"){
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName("Sheet1");
var rg = sh.getDataRange().getValues();
var outString = '';
for(var row=0; row<7 ; ++row){
outString += rg[row].join(',') + '/n';
}
return ContenrService.createTextOutput(outString);
}
// Write from A1 to A6 and read from B1 to B6
else if(e.parameter.func == "WRITE"){
var ss = SpreadsheetApp.getActive();
var sh = ss. getSheetByName("Sheet2");
sh.appendRow([e.parameter.a1,e.parameter.a2,e.parameter.a3,e.parameter.a4,e.parameter.a5,e.parameter.a6]);
var sht = ss. getSheetByName("Sheet1");
var rng = sht.getRange('B1:B6');
var vals = rng.getValues();
return ContentService.createTextOutput(vals);
}
}
Is this code correct ? I don’t really know how to test it.
In app inventor, I would like to :
-> call the READ function of the script
-> add 1
-> call the WRITE function of the script
You also said that I need to build a url to the sheet. I have to use some join text blocks but I cant figure out what part of the link to the script I should write.
My questions are :
What is the url of the script ? (I wrote “something something” istead in the blocks
Am I going the right way ?
here is the link of the script : https://script.google.com/d/1PliiM3sCXtQTrXzy7SbSr9it1EcWPmaMSdTj3VPprkbKvPyrgqbA3UYr/edit?mid=ACjPJvGVXqMGc_EB6MAAC8xwjrEko4GV4Mi-X1-hOdHqf92wEO41kV7w7leJ1GRj8zJjaEB9I0HYOTwWCq5CvS6Rg6IQMqrTLMC2gIxvP3E8gw7--2pvBcQsT6VRuz7MteR3VvijeTyJBlCM&uiv=2
Here is my advancement in app inventor :
To finish, I am sorry if there are ressources online which are already answering my questions. I can’t figure out which words to type in google.
Thanks !