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

164
Visualizações
Matching the search exactly

I'm trying to use app script to give access to my Google sheet by searching through a webpage. so I don't have to give all the data. the search is based on a specific column and the result can be repeatable on the column itself but the other columns of the same row like price and item are different. with my current code if the user searched part of the name or even one letter the results will be all the data containing this letter .. how do I show the data only if it matched with the input from the user.. so I can avoid someone writing the letters from a to z to collect all the data.

function doGet(e) {
  
  return HtmlService.createTemplateFromFile("Index").evaluate()
  .setTitle("WebApp: Search By Password")
  .addMetaTag('viewport', 'width=device-width, initial-scale=1')
  .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}


/* PROCESS FORM */
function processForm(formObject){ 
  var concat = formObject.searchtext;
  var result = "";
  if(concat){//Execute if form passes search text
      result = search(concat);
  }
  return result;
}


function search(searchtext = 'searchtext') {
  let ar = [];
 var spreadsheetId   = '1aN8VLL4iKhGjmM84qhncG9cQfKigCWscMT-UkdzNhQs'; 
  const names = ['Data', 'Data2'];
  names.forEach((name) => {
    var range = SpreadsheetApp.getActive().getSheetByName(name).getDataRange();
    var data = range.getValues();
    data.forEach(function (f) {
    if (~[f[0]].toString().toLowerCase().indexOf(searchtext)) {
      ar.push([f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],f[9]]);
      }
      
    });
  });
  return ar;
};

my coding knowledge is basic so can you help me

thanks a lot

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

0

In order to provide a proper response to the question, I'm writing this answer as a community wiki since the issue was resolved from the comments section.

Changing ~[f[0]].toString().toLowerCase().indexOf(searchtext) to f[0] === searchtext would work but as you mentioned in comments, it worked for names but no for numbers.

In this case try changing it to f[0] == searchtext. Just to give context, using == checks if values are equal while === checks if both type and value match. To give you an example and I imagine this is happening in your case, '1' === 1 will not match because they're not the same type.

References:

Equality (==)

Strict equality (===)

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