Tengo el siguiente script que importa filas a una hoja activa desde la hoja de origen. Después de importar una fila, esa fila se etiqueta como "IMPORTADA" en la hoja de origen. Necesito una condición IF para que si una fila se ha etiquetado como "IMPORTADA", esta fila no se copiará en la hoja activa. El script funciona perfectamente sin la condición IF, pero con la condición IF, el script no se ejecuta.
var ui = SpreadsheetApp.getUi(); ui.createMenu('Import Dockets') .addItem('Import Dockets','deliveries') .addToUi(); } function deliveries(){ // Gets the active sheet. var sheet = SpreadsheetApp.getActiveSheet(); // Gets a different spreadsheet from Drive using // the spreadsheet's ID. var bookSS = SpreadsheetApp.openById( "SHEETID" ); // Gets the sheet, data range, and values of the // spreadsheet stored in bookSS. var bookSheet = bookSS.getSheetByName("DOCKETS"); var lr = bookSheet.getLastRow(); var bookRange = bookSheet.getRange(1,1,lr,58); var bookListValues = bookRange.getValues(); // Add those values to the active sheet in the current // spreadsheet. This overwrites any values already there. var lr = bookSheet.getLastRow(); bookListValues.forEach((r, i) => { var impor = r[56]; if (impor != 'IMPORTED'){ sheet.getRange(1, 1, bookRange.getHeight(), bookRange.getWidth()) .setValues(bookListValues) var lr = bookSheet.getLastRow(); bookSheet.getRange(2,57,lr,1).setValue("IMPORTED"); // Rename the destination sheet and resize the data // columns for easier reading. sheet.setName("DOCKETS"); sheet.autoResizeColumns(1, 25); const ss = SpreadsheetApp.getActive(); const sh = ss.getSheetByName('DOCKETS'); // adjust this to the name of your sheet const values = sh.getRange('F2:F'+sh.getLastRow()).getValues().flat().map(v=>[v.slice(0,v.indexOf(','))]); sh.getRange(2,9,values.length,1).setValues(values); // paste them in column B }Cualquier ayuda es muy apreciada. Gracias
function deliveries() { const ash = SpreadsheetApp.getActiveSheet(); const dss = SpreadsheetApp.openById("SHEETID"); const dsh = dss.getSheetByName("DOCKETS"); const brg = dsh.getRange(1, 1, dsh.getLastRow(), 58); const bvs = brg.getValues(); let arr = []; bvs.forEach((r, i) => { if (r[56] != 'IMPORTED') { arr.push(r); } }) if(arr) { ash.setName("DOCKETS") ash.getRange(2,1,a.length,a[0].length).setValues(a); } }