I am trying to insert a row to the bottom of a sheet, but instead of my values I see text similar to what happens when you try to print an array in Java. I checked to see if the array is made correctly with logger and it has the values I want.
var name = e.range.getRow() + SpreadsheetApp.getActiveSpreadsheet().getName();
var array = e.range.getValues().concat(name);
Logger.log(array.toString());
masterSheet.appendRow(array);
array
contains a timestamp, string1, string2, and finally the name I concatenated. Instead I get something like [Ljava.lang.Object;@7dch7145
It looks like a problem with your use of
getValues()
which returns a two-dimensional array and needs to be accessed as such.GAS API Reference: getValues()
I believe this edit to setting your
var array
should do the trick, assuming your data range is for a single row (index 0 will be the first row, otherwise just change the index to the row you want):This is because
appendRow()
is looking for array[] not array[][].If you attempt to append:
It will show up as the following as it is trying to get the entire contents of the first position of the array in a single cell. It does this by returning a string of the array object which turns out to be the native code identifier.
You can append the contents of array by appending its individual members such as
Would append