Closed jmorim closed 2 years ago
getRange returns an API specified here: https://developers.google.com/apps-script/reference/spreadsheet/range
You can probably use insertCells first to create a new row (given the number of columns), then add the data at the newly inserted row. The pointers would need to be updated to be the second row (right after the header), but should work. Alternatively, there may be a sorting option to sort the data for you. Or you could create a kind of pivot table that auto sorts the data based on time for you too.
If you don't want to mess with the script: On the sheets interface, you can right-click on the letter of your "Timestamp" column (default of the script: A
) and select "Sort Sheet Z to A" from the dropdown - though when the form receives more messages, they would again be added to the bottom, so you would need to do this every time you want newer messages to be at the top.
Replaced
var nextRow = sheet.getLastRow() + 1;
sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
with
var newRow = sheet.getRange(2, 1, 1, newHeader.length);
newRow.insertCells(SpreadsheetApp.Dimension.Rows);
newRow.setValues([row]);
and got it working
I don't know if someone has an easy way of doing this but I imagine it involves messing with the gscript and I don't know how to debug those to get this working quickly. I just want new entries to be at the top of the sheet so I don't have to scroll down for new data. If no one has a quick solution I'll report back if I figure it out.