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

211
Views
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
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!