I ran into troubles trying to make my script work and was wondering if anyone could help me figure it out.
I am working on a simple script in Google Sheets which would overwrite a D column cell in one row if columns A, B, C, E and F are the same for both rows. The screenshot of the example sheet can be seen here. Row 2 is made based on the original reservation, where columns A-F are filled by an external program and columns G and H are later filled by Appsheet. If the reservation status changes, the external program will create a new row with columns A-F with updated reservation status. My idea is to have a script which would replace a cell in the D column of original reservation if it finds another row in data which has the same driver name, car, event, date and duration.
I have tried to base my script on duplicate delete script, but as an output, it deletes the "updated" row without replacing the D cell in the original. Any help would be hugely appreciated!
//overwrite old rows with updated rows
function update() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var newData = new Array();
for(i in data){
var row = data[i];
var update = false;
for(j in newData){
if(row.slice(0,2).join() == newData[j].slice(0,2).join() && row.slice(4,5).join() == newData[j].slice(4,5).join() && row.slice(3).join() !== newData[j].slice(3).join() ){
update = true;
}
}
if(!update){
newData.push(row);
}
}
// Clear the existing info and update with newData.
sheet.clearContents();
sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
}