r/GoogleAppsScript • u/Vegetable_Start9568 • Aug 09 '25
Question I don't understand what I'm doing wrong here
I'm trying to have it so that when I check off a box, it copies the data from the row to a different sheet and then deletes the row. It doesn't do anything when I check off the box. Any thoughts?
3
Upvotes
2
u/WicketTheQuerent Aug 09 '25
The code in the post should throw an error because the
sourcevariable gets assigned a Class Sheet object. This class doesn't havegetSheetByNamemethod.3
u/jdunsta Aug 09 '25
Not sure if I’m correct, but I think line 7 should be let data = ….
The engine recognizes that you’re getting an array from your getRange getValues function.
And even IF you’re declaring an array, it would be more like let data = [] (I never use let, so perhaps this isn’t right either)
Doesn’t let set something permanently so it cannot be changed later?
I would do var data = []; data = sheet.getRange(range).getValues();
2
u/Hinji Aug 09 '25
Firstly, you could add a check to see if the edit occurred where you wanted it to otherwise it's a bunch of wasted API calls.
Secondly, unless you intend to change the values, use
constinstead ofLet.Lastly, you're inserting an array within an array but
appendRowexpects an array and also, your source is referencing the sheet, not spreadsheet. So unless you're actively looking at the archive sheet, the code won't pass the if statement.When in doubt, you can use
Logger.log()for debugging1
u/Chibrax_3000 Aug 09 '25
Destination targets a sheet inherited from source, except that source is already a sheet in my opinion it is blocking, it is that you act on the spreadsheets.
1
u/mommasaidmommasaid Aug 10 '25 edited Aug 10 '25
FWIW, I recommend that you not do this. Just keep everything in one table, and have a status column with your "archive" checkbox or a drodpown.
Put it in an official structured Table and you can create named views/groups to display only the data you want.
That way if your table structure changes you only have to modify it in one place, and you aren't updating/testing script.
And when you inevitably archive something you don't want to, it's simply a matter of unchecking the box. Nothing moves between sheets.
---
But if you must... I'd recommend you avoid hardcoding things in script as much as possible. Use a checkbox with a custom "checked" value and then you won't need to hardcode the source sheet or columns:
Archive Row
Conditional formatting is also used as a progress indicator.