Using Google forms, data can saved to the spreadsheet. Now i would like to apply validation in Username field for avoid duplication. How can add UNIQUE validation in google form field using Google script?
Google Forms automatically assigns a unique, non-sequential and non-guessable identifier (id) to every form entry. This Unique Id contains a mix of alphabets and digits. You can use this unique ID in subject line and message body of your email template with the help of dynamic form fields.
You can add response validation to restrict the answers that users can enter for a question. To add a response validation, select a question in Google Forms, click on ⋮ More icon and select show Response validation. The response validations that you can add varies by question type.
I think it is not possible to add validation for fields in Google form values by using Google Apps Script direcly.
One thing you can consider to change the settings in the Google form itself, if the Username field value is same as the Username that logged in to access that form. You can do this by checking the "only allow one response per person(required login)".
If the above solution does not apply for your requirement, the UiApp/Html Service in Apps Script will help you in creating custom forms.
You can create a custom form and write a custom function to get the Username field values using SpreadsheetApp class into an array. Before submitting the Form, compare the Username field from Google form with the list of username cell values that we got in an array and check for uniqueness.
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With