Syntax error illegal return statement

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);}
}

To start off with....

You should really only have 1 return statement and set a variable for the other outputs to go into it, e.g. something like this:

at the top of your script:

var msg = "Nothing done";

then at the bottom:

if ( getResult != "" ) {
    if ( getPWD == password ) {
        msg = getFullName;
    }
    else { 
       msg = "ERPWD";
   }
   }
else { 
msg = getResult;
}

return ContentService.createTextOutput(msg);

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

Login Details (google.com)

GOD bless...

Also you should be using getValue not getValues for these two....

It's still showing the syntax error. I pay my respect to every IT wizard out there :raised_hands:. Coding is actually frustrating :sob:

You may wish to consider this method as an alternative:

Google Sheets - Register & Login

How do you know you get that error?

Are you running the script from the script editor ? (That will not work, you have to run it from the app)

I am trying to save it on the script editor so I can publish it.
I will grant you access to the script shortly it's taking too long to load

This script works for me:

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.

1 Like

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

Ohhh that makes sense. I also revised your script and I now realize what I had done wrong. You just saved me from a lot of stress thanks a lot :raised_hands:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.