Unify two appscripts in one

Hello, I've been trying and trying to make this with chatGPT but isn't working.

Could you please help me to make one appscript based on this two?
The first script copies the rows with "Revisado" in column G from one sheet to another.

The second script deletes the rows with "Revisado" in column G from the origin sheet.

First, I need to copy the rows and then, delete the rows.

Copy script:

function CopiarAHistorialPreciosRevisados() {
  var origenLibro = SpreadsheetApp.openById("18F590qV81wP3AmCH7MVU6c43Y2aDXvQzFrNQwVwijk0");
  var origenHoja = origenLibro.getSheetByName("Copia de CambioPrecio");
 
  var destinoLibro = SpreadsheetApp.openById("1GwHN5gDZPHoikQ3aIGzpyf2g-D_7MCk56rCtCC78wUM");
  var destinoHoja = destinoLibro.getSheetByName("HistorialCambioPrecio");
 
  var datosOrigen = origenHoja.getDataRange().getValues();
  var datosDestino = [];
 
  for (var i = 1; i < datosOrigen.length; i++) {
    if (datosOrigen[i][6].toLowerCase().indexOf("revisado") !== -1) {
      datosDestino.push(datosOrigen[i]);
    }
  }
 
  if (datosDestino.length > 0) {
    destinoHoja.getRange(destinoHoja.getLastRow() + 1, 1, datosDestino.length, datosDestino[0].length).setValues(datosDestino);
    Logger.log("Se han copiado " + datosDestino.length + " filas a la hoja de destino.");
  } else {
    Logger.log("No se encontraron filas que cumplan con los criterios de bรบsqueda.");
  }
}
 
 
Delete script:
function EliminarPreciosRevisados() {
  var libro = SpreadsheetApp.openById("18F590qV81wP3AmCH7MVU6c43Y2aDXvQzFrNQwVwijk0");
  var hoja = libro.getSheetByName("Copia de CambioPrecio");
  var datos = hoja.getDataRange().getValues();
 
  for (var i = datos.length - 1; i > 0; i--) {
    if (datos[i][6] === "Revisado") { // Columna G es la sรฉptima columna (0-indexed)
      hoja.deleteRow(i + 1);
    }
  }
}
2 0 40
0 REPLIES 0
Top Solution Authors