Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

509
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!