¡Hola! Uso una hoja de cálculo con listas desplegables dependientes. Cuando la hoja era pequeña, todo estaba bien, pero ahora ni siquiera puedo ejecutarla. Hay muchos Quizás necesiten una optimización para mi script. Recién comencé a usar Google Apps Script y no sé cómo escribir códigos correctamente. Entonces, si cometí un error, hágamelo saber o si cometí un error al publicarlo.
let colShift = 5; function onEdit(e) { let row = e.range.getRow(); let col = e.range.getColumn(); let sheetName = e.source.getActiveSheet().getName(); let name = e.value; let oldName = e.oldValue; let sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet_1"); let mask = JSON.stringify(sh.getRange(row, colShift+1, 1, col-colShift).getValues()[0]); let colMax = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet_2").getLastColumn(); if(sheetName === "sheet_1" && name !== oldName && col < colMax+colShift) { fillColumn(row, col, mask); } } function fillColumn(row, col, mask) { let col_data = col - colShift; // clear dataVal and Value let sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet_1"); let colMax = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet_2").getLastColumn(); sh.getRange(row, col+1, 1, colMax-col_data).clearDataValidations().clearContent(); // find data let sd = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet_2"); let arrData = sd.getDataRange().getValues(); let arrData_2 = []; let iMax = arrData.length - 1; for(let i=1; i<=iMax; i++) { if(JSON.stringify(arrData[i].slice(0, col_data)) == mask) { arrData_2.push(arrData[i].slice(0, col_data+1)); } } arrData_2 = arrData_2.map(item => item.pop()); let uniqArrData_2 = arrData_2.filter(uniqValues); // add dataVal col++; sh.getRange(row, col).setDataValidation(SpreadsheetApp.newDataValidation() .setAllowInvalid(false) .requireValueInList(uniqArrData_2, true) .build()); } function uniqValues(item, index, arr) { return arr.indexOf(item) === index; }