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

83
Visualizações
get values ​from one or more rows matching an index value in google apps script

I am trying the following:

Look for this value of the sheet "Pedidos" in the rows of the sheet "Pedidos articulos". When you find one or more rows matches that contain these search value, then get the values ​​for the entire row.

I need to get the data ​​of the matching rows, however, I don't need to paste them anywhere on the sheet, since this function is to display this data in a modaldialog html template through Scriptlets.

What's my problem:

My problem is that I have managed to find the matches of the value (numPedido) in the "Pedidos articulos" sheet, however, it always returns the index of the matching rows. I can't get the data for those matching rows.

My code:

function obtenerProductos3(){

  //Hoja Pedidos

  var hojaPedidos = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Pedidos');
  var fila = hojaPedidos.getCurrentCell().getRow();
  var numeroPedidoPE = hojaPedidos.getRange(fila,3,1,1).getDisplayValue();
  Logger.log(numeroPedidoPE)

  //Hoja Pedidos artículos

  var hojaPedidosArticulos = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Pedidos Artículos'); 
  var numPedidoAR = hojaPedidosArticulos.getRange('C7:C').getValues();
  var articulos = hojaPedidosArticulos.getRange(7,3, hojaPedidosArticulos.getLastRow()-6, hojaPedidosArticulos.getLastColumn()-1).getValues();

  //var articulos = hojaPedidosArticulos.getRange('C7:O').getDisplayValues();

  Logger.log(numPedidoAR)
  Logger.log(articulos)
  
  var newData =  articulos.map(function(r){ return r[0]; });
  Logger.log(newData)

  var indexes = newData.map((element, i) => element === numeroPedidoPE ? i : "")
                      .filter(element => element !== "");

  Logger.log(indexes)
  
  return (hojaPedidosArticulos.getRange(indexes, 2, indexes, hojaPedidosArticulos.getLastColumn()).getDisplayValues());


}

All help is greatly appreciated.

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

0

indexes is an array. Please iterate it.

  const values = hojaPedidosArticulos.getRange(7, 2, hojaPedidosArticulos.getLastRow() - 6, hojaPedidosArticulos.getLastColumn() - 1).getDisplayValues();
  const results = values.filter((e, i) => indexes.includes(i));
  return results;
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