Utilizing Google Apps Script, I am retrieving data from another spreadsheet and storing it daily in a sheet named "DATABASE".
Although my current solution is basic, it keeps overwriting existing data. I wish to enhance the script to copy data from the imported range spreadsheet to a specific column and continue copying it to the next empty row without erasing any previously copied data. Can someone please assist me with this?
var scriptProperties = PropertiesService.getScriptProperties();
var ssid = '1usRuvazJlxAGvF0G2-e00MEQ_AjMCOnWopBFX4qfUcc';
var sheetName = 'DATABASE';
function CopyDatabase() {
var sheet = SpreadsheetApp.openById(ssid).getSheetByName(sheetName);
var startRow = 3;
var numRows = sheet.getLastRow() - 1;
var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
var data = dataRange.getValues();
var Copy = "Copy";
var newRow = sheet.getLastRow() + 1;
for (var i = 0; i < data.length; ++i) {
var row = data[i];
if (row[5] != Copy) {
var Code = row[0];
var orderDate = row[1];
var custName = row[2];
sheet.getRange(startRow + i, 5).setValue(Code);
sheet.getRange(startRow + i, 6).setValue(orderDate);
sheet.getRange(startRow + i, 7).setValue(custName);
}
}
}
Here is the link to the database (Google sheet):
https://docs.google.com/spreadsheets/d/1usRuvazJlxAGvF0G2-e00MEQ_AjMCOnWopBFX4qfUcc/edit#gid=0