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

212
Visualizações
how can I check if an entry already exists before its captured

I would like to validate an entry before it adds as a record by checking the student ID in "UserForm" against an array in "SDB" and if it finds a match to pop up with an error. At the moment I can add the same student multiple times which I would like to prevent.

function validateEntry() {
  var myGooglSheet= SpreadsheetApp.getActiveSpreadsheet();
  var shUserForm = myGooglSheet.getSheetByName("User Form");
  var datasheet = myGooglSheet.getSheetByName("SDB");
  var ui = SpreadsheetApp.getUi();
    
  //Validating Student Id
    
  if(shUserForm.getRange("S1") = SDB.getRange(A:A)) {
    ui.alert("Already Exists.");
    shUserForm.getRange("S1").activate();
    shUserForm.getRange("S1").setBackground('#FF0000');
    return false;
  }  
  return true;
}

Any help would be great!

Edit:Found a workaround for it by checking if the entry exists in google spreadsheets with a formula;

=IFERROR(if(vlookup(S1,SDB!A:A,1,false)=vlookup(S1,SDB!A:A,1,false),"Modify",""),"NEW")

and then running the script to check the formula

//Validating Student Id
  if(shUserForm.getRange("O1").getValue()=="Modify") {
    ui.alert("Entry Already Exists.");
    shUserForm.getRange("O1").activate();
    shUserForm.getRange("O1").setBackground('#FF0000');
    return false;
  }

It does the trick but still a one step method would be ideal!

about 4 years ago · Juan Pablo Isaza
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