I keep getting a message that the parameter is not defined. What am I doing wrong? I am new to Google Appscript and I am just trying to build a simple web application that stores First Name and Last Name to a spreadsheet.
Here is the link to the web-app: https://script.google.com/macros/s/AKfycbwwQts-izTP6MTWRM64948Gskf6MMktO07bTw_55qD9kZXOy17c/exec
function doGet(e){
Logger.log(e);
var FS = e.parameter.Fname;
var LS = e.parameter.Lname;
savedata(FS,LS);
}
function savedata(FS,LS) {
var date = new date(); //gets new date
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/1f2oIAuOt8PoAEtQW5zr6GJDwpPKl8doKhmECDEaHXl4/edit#gid=0';
var worksheet = ss.getSheetByName("logs1");
var cur_row = worksheet.getLastRow() + 1;
worksheet.getActiveRange("A" + cur_row).setValue(cur_row);
worksheet.getActiveRange("B" + cur_row).setValue(date);
worksheet.getActiveRange("C" + cur_row).SetValue(FS);
worksheet.getActiveRange("D" + cur_row).SetValue(LS);
}
The event object's parameter property cannot be "undefined" on get request as event object always has the following structure (without any query parameters):
Since you get the message that parameter is not defined, you most likely try to run
doGet()
from the editor - you should not do that as event object is constructed only if you access the url from the browser or send http request programmatically (in the last case not specifying query at all or mistyping a param won't result in this message as well).Plus,
getActiveRange()
method does not accept any args, maybe you meantsetActiveRange()
? If so, you also need to wrap eachRange
reference inworksheet.getRange(yourRangeString)
(and consider using cost-effectivesetValues(ArrayOfValues)
method instead on range"A"+cur_row+":D"+cur_row
).Overall, your code should look like this (minus the test getSelf() function):
Btw, if you want others to be able to access your current deployment, be sure to change publishing setting from "only myself" to "anyone" or "anyone, even anonymous".