I believe your goal is as follows.
- You want to copy the values from column "A" to column "D" on the same sheet on Google Spreadsheet.
- When the values are copied, you want to append only the new values to column "D".
- You want to achieve this using Google Apps Script.
In this case, how about the following sample script?
Sample script:
Please copy and paste the following script to the script editor of Google Spreadsheet. And, please set your sheet name, and save the script.
function myFunction() {
const sheetName = "Sheet1"; // Please set your sheet name.
// Ref: https://stackoverflow.com/a/44563639
Object.prototype.get1stNonEmptyRowFromBottom = function (columnNumber, offsetRow = 1) {
const search = this.getRange(offsetRow, columnNumber, this.getMaxRows()).createTextFinder(".").useRegularExpression(true).findPrevious();
return search ? search.getRow() : offsetRow;
};
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
const values = sheet.getRange("A1:D" + sheet.getLastRow()).getValues();
const colD = new Map(values.map(([, , , d]) => [d, d]));
const addValues = values.flatMap(([a]) => (a.toString() == "" || colD.has(a)) ? [] : [[a]]);
if (addValues.length == 0) return;
sheet.getRange(sheet.get1stNonEmptyRowFromBottom(4) + 1, 4, addValues.length).setValues(addValues);
}
Testing:
When this script is run, the following result is obtained.

References: