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

98
Visualizações
Inserting an IF condition

I have the following script which imports rows to an Active sheet from the Source sheet. After a row is imported that row is labelled "IMPORTED" own the source sheet. I require an IF condition so that if a row has been labelled "IMPORTED" this row will not copy to the Active Sheet. The script works perfect without the IF condition, but with the IF condition the script fails to run.

  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
   
}

Any assistance is much appreciated. Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try it this way

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