Table of Contents
Overview
This is a small sample project to show you how to use Apps Script to do data entry in google sheet.
Make a copy of the sample project file. Watch Demo
Preparing our data entry form
-This is how our form looks -The drop-down fields in our form takes data from Dropdowns tab of the Spreadsheet. -See below how we validate our drop-down
Apps Script Code to handle data entry
Code.gs
function SUBMIT_FORM_3() {
const FORM_SHEET_NAME = "Form 3";
const FORM_RANGE_ARRAY = ['B4','B6','D4','D6'];
const RECORD_SHEET_NAME = "Record";
const formSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(FORM_SHEET_NAME);
const recordSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(RECORD_SHEET_NAME);
// Get Form Data
const formData = FORM_RANGE_ARRAY.map(el=>formSheet.getRange(el).getValue()); //
console.log(formData);
// Check if all the fields are filled
const isFormFilled = formData.includes('');
if (!isFormFilled) {
// Add form data to record
recordSheet.appendRow(formData);
// Clear Form
FORM_RANGE_ARRAY.forEach(el=>formSheet.getRange(el).clearContent());
} else {
Browser.msgBox("Please fill all the details!");
}
}