swolfe2
swolfe2

Reputation: 451

Google Apps Script - Append Array of Variables to Sheet

I've got the following code that grabs all of the information I need form the active line, and puts them into an array of variables. However, I can't seem to find good documentation on how to append the variables to a another sheet in the same document:

function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
var spreadsheetTimeZone = SpreadsheetApp.getActive().getSpreadsheetTimeZone();
var lastUpdatedString = Utilities.formatDate(new Date(), spreadsheetTimeZone, "MM/dd/yyyy' 'HH:mm:ss");
var sessionEmail = Session.getActiveUser().getEmail();

if (s.getName() == "Workload") { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    if (r.getColumn() == 14) { //checks the column
        var status = r.getValue();
        var note = r.offset(0, -1);
        var noteValue = note.getValue()
        var delivery = r.offset(0, -5);
        var deliveryValue = delivery.getValue()

    }
    var array = [lastUpdatedString, sessionEmail, deliveryValue, noteValue]
    // get destination range

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var pasteSheet = ss.getSheetByName("Historical Notes Sheet");
    var destination = pasteSheet.getRange(pasteSheet.getLastRow() + 1, 1, 1, 1);

}

}

I'd like to append the values from var array into the "Historical Notes Sheet", in the same order they are in the array.

Any help/advice you all could provide would be greatly appreciated.

Thanks!

Upvotes: 0

Views: 1217

Answers (1)

Anton Dementiev
Anton Dementiev

Reputation: 5716

Try this

pasteSheet.appendRow(array);

More info https://developers.google.com/apps-script/reference/spreadsheet/sheet#appendRow(Object)

Upvotes: 1

Related Questions