Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!