1
votes

Is there a way of returning the newly appended row number into a Google sheet with the following appendRow code? I can guarantee that the sheet will not be sorted but I cannot guarantee that the sheet will not have another row append before I call the number of rows of data in the sheet.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Appends a new row with 3 columns to the bottom of the
// spreadsheet containing the values in the array
sheet.appendRow(["a man", "a plan", "panama"]);
1

1 Answers

2
votes

appendRow() returns the Sheet object for chaining. If you want the row number, you need to call getLastRow() (see docs) immediately after appending. If you have concurrent appends, you can use the Lock Service to make sure to avoid conflicts.