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"
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);
}