r/GoogleAppsScript • u/Gryphacus • Jan 14 '21
Resolved First time user: Apps Script won't let me save anything, even default/blank function
Hi all, please forgive my lack of knowledge as I'm sure I'm just making a stupid mistake. I'm trying to write an onEdit function for a spreadsheet, but when I try to save I keep getting the error,
Syntax error: SyntaxError: Invalid or unexpected token line: 1 file: Code.gs
I have no clue what I am doing wrong. My code looks exactly like every example/video/etc. I can find... Here's the function:
function onEdit(evt) {
var ss = SpreadsheetApp.getActiveSheet();
var r = evt.range;
if (r.getColumn() > 2 && ss.getName()=='Sheet1') {
var datecelladdress = 'A'+ r.getRowIndex();
var timecelladdress = 'B'+ r.getRowIndex();
ss.getRange(datecelladdress).setValue(new Date()).setNumberFormat("MM/dd/yyyy");
ss.getRange(timecelladdress).setValue(new Date()).setNumberFormat("hh:mm");
}
}Even if I create a new blank script, with nothing except "function myFunction() {}", it gives me the same syntax error.
1
u/Wishyouamerry May 28 '21
I'm so glad you answered this post yourself and left it up. The same thing just happened to me. I backspaced in front of function, and BAM! Problem solved!
Thank you!
5
u/Gryphacus Jan 14 '21
Well, I suppose I'm just an idiot? Apparently, there was an invisible character before my function declaration. Pressing backspace in front of the function was enough to solve the issue.