Reputation: 527
No matter what i do, i get the error in the title. If i replace my script with the standard
function doGet(e) {
var params = JSON.stringify(e);
return HtmlService.createHtmlOutput(params);
}
from Googles very own example: https://developers.google.com/apps-script/guides/web#url_parameters i have to run it once (inside the script editing thingy) to not show the error anymore, but when i put my code back in place it stays at the output of that dummy function. Probably because i cannot run my own function without errors (see below).
Settings for the web-app deployment:
I think it has something to do with having to run a function once (or atleast that's what it looks like to me), but i cannot run my function since it's relying on url parameters. This already fails at e.parameter == undefined obviously.
function doGet(e) {
Logger.log(JSON.stringify(e));
var result = 'Ok';
if(e.parameter == undefined) {
result = 'no param';
}
else {
var id = 'id is normally here obviously not now';
var sheet = SpreadsheetApp.openById(id).getActiveSheet();
var newRow = sheet.getLastRow()+1;
var rowData = [];
for (var param in e.parameter) {
var value = stripQuotes(e.parameter[param]);
Logger.log(param + ': ' + e.parameter[param]);
switch (param) {
case 'timeStampBegin': //Parameter
rowData[0] = value; //Value in column B
break;
case 'timeStampEnd':
rowData[1] = value;
break;
default:
result = 'unsupported parameter';
}
}
Logger.log(JSON.stringify(rowData));
var newRange = sheet.getRange(newRow, 1, 1, rowData.length);
newRange.setValues([rowData]);
}
return ContentService.createTextOutput(result);
}
function stripQuotes( value ) {
return value.replace(/^["']|['"]$/g, "");
}
I appreciate any suggestions why this could be happening or how i could run my function with a test input.
Upvotes: 0
Views: 2688
Reputation: 916
You do need to run your script once in the IDE after you add any new services (e.g. HTML service, spreadsheet service, etc.) to approve those changes from a security standpoint.
To test your code without making tons of new versions and deploying each one (i.e. steps 2-3), you can either run it in the web IDE, or navigate to "Publish" > "Deploy as web app..." then click on "Test web app for your latest code." Unlike the live version, that link uses whatever code is currently saved, not the last deployed version.
Upvotes: 2
Reputation: 527
I don't know of this is intentional by Google, but this is kinda ridiculous. Apparently a function has to be run once in the editor to be able to used. But here it is anyway:
I'm not sure 2+3 are really necessary, but for me it still ran the old dummy code (print back json) without doing that.
Upvotes: 1