Can anyone please help me out. Apparently there's an illegal return statement on my script and I cant seem to figure out the problem.
I put it in bold below. Any help would be really appreciated. Thank you in avance
if (e.parameter.func == "Login") {
var ss = SpreadsheetApp.openById(e.parameter.ID);
var sh = ss.getSheetByName(e.parameter.SH);
var email = e.parameter.email;
var password = e.parameter.password;
var rg = sh.getName() + "!" + sh.getDataRange().getA1Notation();
var sql = '"Select A,B,C where B=''+email+''"';
var qry = '=IFERROR(query(' + rg + ',' + sql + '),"")';
var ts = ss.insertSheet();
var setQuery = ts.getRange(1,1).setFormula(qry);
var getResult = ts.getDataRange().getValues();
var getPWD = ts.getRange(1,3).getValues();
var getFullName = ts.getRange(1,1).getValues();
ss.deleteSheet(ts);
if (getResult!=""){ if (getPWD==password){return ContentService.createTextOutput(getFullName);}
else { return ContentService.createTextOutput("ERPWD");}
}
else{return ContentService.createTextOutput(getResult);}
}
I don't know how my head hasn't exploded but it surely will if I try to figure this out any longer.
I'm actually a Law student and I am attending programming classes on Shaw Academy but i missed my latest thus I am confused. if you don't mind can you please take a look at it here
function doGet(e) {
if (e.parameter.func == "Login") {
var ss = SpreadsheetApp.openById(e.parameter.ID);
var sh = ss.getSheetByName(e.parameter.SH);
var msg = 'Nothing';
var email = e.parameter.email;
var password = e.parameter.password;
var rg = sh.getName() + "!" + sh.getDataRange().getA1Notation();
var sql = "Select A,B,C where B ="+" '"+ email +"'";
var qry = '=query(' + rg + ';\"' + sql + '\";0)';
var ts = ss.insertSheet();
var setQuery = ts.getRange(1,1).setFormula(qry);
var getResult = ts.getDataRange().getValues();
var getPWD = ts.getRange(1,3).getValue();
var getFullName = ts.getRange(1,1).getValue();
ss.deleteSheet(ts);
if ( getPWD == password ) {
msg = getFullName;
}
else {
msg = 'ERPWD';
}
return ContentService.createTextOutput(msg);
}
}
Be aware, the new google apps script editor may create a new script url when you update your script code and create a new deployment, you will need to copy this over to your app.
Thanks a lot Tim it worked. Also, I might need to avoid such errors in future and somewhere above you said running the script from the script editor won't work, I have to run it from the app? I'm not sure I understood that part, also I'm very sorry for bothering you I'm quite new to this world. I really appreciate everything Tim
Because your web app requires parameters to run e.g. the email address and the password, these are not passed when you run the script in the script editor. Therefore you have to send the script url with all the parameters if you want it to work. The easiest way to do this is to use your app. (For testing in the script editor, you could always replace the parameters - e.g. e.parameter.email, with a text.)
If you use doGet(e) in your script, you can construct a url and test in your browser, if you use doPost(e) the either use the app or something like curl or Postman