Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

511
Vistas
Google Apps Script - row not deleting after script

Now, about an hour ago someone here was kind enough to help me solve a problem i had with GApps Script, now, while trying to fix/add some stuff, uhhhhh i dont think it works anymore, at least in a certain part. So, lemme explain, this is the code so far. Its supposed to check several cases and if the condition is true, it copies those rows from one sheet to the other, this works perfectly, however, (and this used to work i think, so idk why it doesnt work now) the rows that have been copied dont get deleted after that, why is that?

  var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("NUEVOS INGRESOS Y EXPEDIENTES EN TRAMITE");
  var archive = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CASOS ARCHIVADOS/FINALIZADOS");
  if (sourceSheet.getLastRow()==1){
    SpreadsheetApp.getActive().toast('No data!', 'End of script 🗃️')
    return
  }
  var data = sourceSheet.getRange(2,1,sourceSheet.getLastRow()-1,sourceSheet.getLastColumn()).getValues()
  var archiveData = []
  var lines = []
  var line = 1
  var col = 31 // AF
  try {
    data.forEach(function (row) {
      if (row[col]=="Finalizado_Archivado") {
        archiveData.push(row)
        lines.push(line)
      }
      else if(row[col]=="Remitida_a_otro_juzgado_conexidad"){
        archiveData.push(row)
        lines.push(line)
      }
      else if(row[col]=="Remitida_UACF"){
        archiveData.push(row)
        lines.push(line)
      }
      else if(row[col]=="Remitida_a_otro_juzgado_por_recusacion"){
        archiveData.push(row)
        lines.push(line)
      }
      else if(row[col]=="Remitida_a_otro_Juzgado_por_cuestion_de_turno"){
        archiveData.push(row)
        lines.push(line)
      }
      else if(row[col]=="Remitida_a_otros_fueros"){
        archiveData.push(row)
        lines.push(line)
      }     
    })
    archive.getRange(archive.getLastRow() + 1, 1, archiveData.length, archiveData[0].length).setValues(archiveData)
    lines.reverse().forEach(x => sourceSheet.deleteRow(x));
    SpreadsheetApp.getActive().toast('Rows '+lines.flat()+' hab been archived !', 'End of script 🗃️')
  } catch (e) {
    SpreadsheetApp.getActive().toast('No data to be archived!', 'End of script 🗃️')
  }
} 

// || "Remitida_a_otro_juzgado_conexidad"||"Remitida_UACF"||"Remitida_a_otro_juzgado_por_recusacion"||
//"Remitida_a_otro_Juzgado_por_cuestion_de_turno"||"Remitida_a_otros_fueros"

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try this:

function elfunko() {
  const ss = SpreadsheetApp.getActive();
  const ssh = ss.getSheetByName("Sheet1");//Changed sheet name
  const ash = ss.getSheetByName("Sheet2");
  const spA = ["Finalizado_Archivado", "Remitida_a_otro_juzgado_conexidad", "Remitida_UACF", "Remitida_a_otro_juzgado_por_recusacion", "Remitida_a_otro_Juzgado_por_cuestion_de_turno", "Remitida_a_otros_fueros"];
  if (ssh.getLastRow() == 1) {
    SpreadsheetApp.getActive().toast('No data!', 'End of script 🗃️');
    return;
  }
  const vs = ssh.getRange(2, 1, ssh.getLastRow() - 1, ssh.getLastColumn()).getValues()
  const archiveData = [];
  let d = 0;//delete counter
  vs.forEach((r, i) => {
    if (~spA.indexOf(r[31])) {
      archiveData.push(r);
      ssh.deleteRow(i + 2 - d++);
    }
  });
  ash.getRange(ash.getLastRow() + 1, 1, archiveData.length, archiveData[0].length).setValues(archiveData);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda