Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

510
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda