0% found this document useful (0 votes)
8 views8 pages

Google Apps Script User Form Guide

Uploaded by

wbxtoys
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Google Apps Script User Form Guide

Uploaded by

wbxtoys
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Data Entry Form - Google Apps Script Code

// Function to Clear the User Form

function clearForm()
{
var myGoogleSheet= [Link](); //declare
a variable and set with active google sheet
var shUserForm = [Link]("User Form");
//declare a variable and set with the User Form worksheet

//to create the instance of the user-interface environment to use


the alert features
var ui = [Link]();

// Display a dialog box with a title, message, and "Yes" and "No"
buttons. The user can also
// close the dialog by clicking the close button in its title bar.
var response = [Link]("Reset Confirmation", 'Do you want to reset
this form?',[Link].YES_NO);

// Checking the user response and proceed with clearing the form if
user selects Yes
if (response == [Link])
{

[Link]("C4").clear(); //Search Field


[Link]("C7").clear();// Employeey ID
[Link]("C9").clear(); // Employee Name
[Link]("C11").clear(); // Gender
[Link]("C13").clear(); // Email ID
[Link]("C15").clear(); //Department
[Link]("C17").clear();//Address

//Assigning white as default background color

[Link]("C4").setBackground('#FFFFFF');
[Link]("C7").setBackground('#FFFFFF');
[Link]("C9").setBackground('#FFFFFF');
[Link]("C11").setBackground('#FFFFFF');
[Link]("C13").setBackground('#FFFFFF');
[Link]("C15").setBackground('#FFFFFF');
[Link]("C17").setBackground('#FFFFFF');
return true ;

}
}
// Function to submit the data to Database sheet

function submitData() {

var myGooglSheet= [Link](); //declare


a variable and set with active google sheet

var shUserForm= [Link]("User Form"); //delcare


a variable and set with the User Form worksheet

var datasheet = [Link]("Database");


////delcare a variable and set with the Database worksheet

//to create the instance of the user-interface environment to use


the messagebox features
var ui = [Link]();

// Display a dialog box with a title, message, and "Yes" and "No"
buttons. The user can also
// close the dialog by clicking the close button in its title bar.
var response = [Link]("Submit", 'Do you want to submit the
data?',[Link].YES_NO);

// Checking the user response and proceed with clearing the form if
user selects Yes
if (response == [Link])
{return;//exit from this function
}

//Validating the entry. If validation is true then proceed with


transferring the data to Database sheet
if (validateEntry()==true) {

var blankRow=[Link]()+1; //identify the next blank


row

[Link](blankRow,
1).setValue([Link]("C7").getValue()); //Employee ID
[Link](blankRow,
2).setValue([Link]("C9").getValue()); //Employee Name
[Link](blankRow,
3).setValue([Link]("C11").getValue()); //Gender
[Link](blankRow,
4).setValue([Link]("C13").getValue()); // Email ID
[Link](blankRow,
5).setValue([Link]("C15").getValue()); //Department
[Link](blankRow,
6).setValue([Link]("C17").getValue());// Address

// date function to update the current date and time as submittted


on
[Link](blankRow, 7).setValue(new
Date()).setNumberFormat('yyyy-mm-dd h:mm'); //Submitted On

//get the email address of the person running the script and update
as Submitted By
[Link](blankRow,
8).setValue([Link]().getEmail()); //Submitted By

[Link](' "New Data Saved - Emp #' +


[Link]("C7").getValue() +' "');

//Clearnign the data from the Data Entry Form

[Link]("C7").clear();
[Link]("C9").clear();
[Link]("C11").clear();
[Link]("C13").clear();
[Link]("C15").clear();
[Link]("C17").clear();

}
}

//Function to Search the record

function searchRecord() {

var myGooglSheet= [Link](); //declare


a variable and set with active google sheet
var shUserForm= [Link]("User Form"); //delcare
a variable and set with the User Form worksheet
var datasheet = [Link]("Database");
////delcare a variable and set with the Database worksheet
var str = [Link]("C4").getValue();
var values = [Link]().getValues(); //getting the
entire values from the used range and assigning it to values
variable
var valuesFound=false; //variable to store boolean value

for (var i = 0; i < [Link]; i++)


{
var rowValue = values[i]; //declaraing a variable and storing the
value

//checking the first value of the record is equal to search item


if (rowValue[0] == str) {

[Link]("C7").setValue(rowValue[0]) ;
[Link]("C9").setValue(rowValue[1]);
[Link]("C11").setValue(rowValue[2]);
[Link]("C13").setValue(rowValue[3]);
[Link]("C15").setValue(rowValue[4]);
[Link]("C17").setValue(rowValue[5]);
return; //come out from the search function

}
}

if(valuesFound==false){
//to create the instance of the user-interface environment to use
the messagebox features
var ui = [Link]();
[Link]("No record found!");
}

//Function to delete the record

function deleteRow() {

var myGooglSheet= [Link](); //declare


a variable and set with active google sheet
var shUserForm= [Link]("User Form"); //delcare
a variable and set with the User Form worksheet
var datasheet = [Link]("Database");
////delcare a variable and set with the Database worksheet
//to create the instance of the user-interface environment to use
the messagebox features
var ui = [Link]();

// Display a dialog box with a title, message, and "Yes" and "No"
buttons. The user can also
// close the dialog by clicking the close button in its title bar.
var response = [Link]("Submit", 'Do you want to delete the
record?',[Link].YES_NO);

// Checking the user response and proceed with clearing the form if
user selects Yes
if (response == [Link])
{return;//exit from this function
}

var str = [Link]("C4").getValue();


var values = [Link]().getValues(); //getting the
entire values from the used range and assigning it to values
variable

var valuesFound=false; //variable to store boolean value to


validate whether values found or not

for (var i = 0; i < [Link]; i++)


{
var rowValue = values[i]; //declaraing a variable and storing the
value

//checking the first value of the record is equal to search item


if (rowValue[0] == str) {

var iRow = i+1; //identify the row number


[Link](iRow) ; //deleting the row

//message to confirm the action


[Link](' "Record deleted for Emp #' +
[Link]("C4").getValue() +' "');

//Clearing the user form


[Link]("C4").clear() ;
[Link]("C7").clear() ;
[Link]("C9").clear() ;
[Link]("C11").clear() ;
[Link]("C13").clear() ;
[Link]("C15").clear() ;
[Link]("C17").clear() ;

valuesFound=true;
return; //come out from the search function
}
}

if(valuesFound==false){
//to create the instance of the user-interface environment to use
the messagebox features
var ui = [Link]();
[Link]("No record found!");
}

//Function to edit the record

function editRecord() {

var myGooglSheet= [Link](); //declare


a variable and set with active google sheet
var shUserForm= [Link]("User Form"); //delcare
a variable and set with the User Form worksheet
var datasheet = [Link]("Database");
////delcare a variable and set with the Database worksheet

//to create the instance of the user-interface environment to use


the messagebox features
var ui = [Link]();

// Display a dialog box with a title, message, and "Yes" and "No"
buttons. The user can also
// close the dialog by clicking the close button in its title bar.
var response = [Link]("Submit", 'Do you want to edit the
data?',[Link].YES_NO);

// Checking the user response and proceed with clearing the form if
user selects Yes
if (response == [Link])
{return;//exit from this function
}

var str = [Link]("C4").getValue();


var values = [Link]().getValues(); //getting the
entire values from the used range and assigning it to values
variable

var valuesFound=false; //variable to store boolean value to


validate whether values found or not

for (var i = 0; i < [Link]; i++)


{
var rowValue = values[i]; //declaraing a variable and storing the
value

//checking the first value of the record is equal to search item


if (rowValue[0] == str) {

var iRow = i+1; //identify the row number

[Link](iRow,
1).setValue([Link]("C7").getValue()); //Employee ID
[Link](iRow,
2).setValue([Link]("C9").getValue()); //Employee Name
[Link](iRow,
3).setValue([Link]("C11").getValue()); //Gender
[Link](iRow,
4).setValue([Link]("C13").getValue()); // Email ID
[Link](iRow,
5).setValue([Link]("C15").getValue()); //Department
[Link](iRow,
6).setValue([Link]("C17").getValue());// Address

// date function to update the current date and time as submittted


on
[Link](iRow, 7).setValue(new
Date()).setNumberFormat('yyyy-mm-dd h:mm'); //Submitted On

//get the email address of the person running the script and update
as Submitted By
[Link](iRow,
8).setValue([Link]().getEmail()); //Submitted By

[Link](' "Data updated for - Emp #' +


[Link]("C7").getValue() +' "');
//Clearnign the data from the Data Entry Form

[Link]("C4").clear();
[Link]("C7").clear();
[Link]("C9").clear();
[Link]("C11").clear();
[Link]("C13").clear();
[Link]("C15").clear();
[Link]("C17").clear();

valuesFound=true;
return; //come out from the search function
}
}

if(valuesFound==false){
//to create the instance of the user-interface environment to use
the messagebox features
var ui = [Link]();
[Link]("No record found!");
}

Common questions

Powered by AI

User confirmations play a crucial role in improving script robustness by acting as a safeguard against unintended actions. Each critical operation, such as resetting forms, submitting, deleting, or editing records, is accompanied by a confirmation alert requiring the user to acknowledge the action. This interaction adds a level of verification that mitigates errors and potential data loss or corruption, thereby enhancing the reliability of the script while fostering user trust and clarity during data operations.

User feedback via alerts in Google Apps Script enhances the user interface by ensuring clear communication between the script and the user. Alerts confirm actions such as submitting data, resetting forms, or editing records, which helps in minimizing user errors and managing expectations. This direct interaction prompts user acknowledgment, creating a smoother operational flow and ensuring that users are aware of the actions being taken within the script.

The deleteRow function primarily ensures correct data deletion by first prompting the user for confirmation through a dialog box. It then checks if the search item exists in the database by iterating over each record and comparing the first column of each row with the user-provided search value. If a match is found, it deletes the corresponding row and alerts the user regarding successful deletion. If no match is found, an alert indicating 'No record found!' is displayed.

The searchRecord function emphasizes the relationship between search criteria and database entries by iterating over all records in the database and comparing the search field value (provided by the user in the form) with the first column of each record in the database sheet. Upon finding a match, it populates the form fields with the corresponding record details, thus establishing a dynamic link between user input and stored data. If no match is found, it prompts the user with a 'No record found!' alert.

The clear function contributes to data security by removing any residual data from the Google Sheet upon form submission or when the clear form function is executed. By clearing fields such as Employee ID, Name, Gender, Email ID, Department, and Address, it prevents unauthorized access to sensitive information that might be left in the form. It also reduces the risk of data mix-up during subsequent entries by ensuring that each form submission starts with clean, empty fields.

When no records are found, the searchRecord function employs a boolean variable to track if any matching record was found during the iteration. If no match occurs, it shows an alert message 'No record found!' to the user, providing immediate feedback and helping to understand that the desired search result was not in the database. This handles potential user confusion and ensures clarity in the search process.

Data backup implicitly occurs through the historical record-keeping in the database sheet every time data is submitted. Each submission creates a new row with time-stamped data and user information, effectively logging all changes and submissions. This structured approach to data logging acts as an implicit form of backup, allowing retrieval and review of past data submissions if needed.

To reset a user form in Google Apps Script, the script first prompts for user confirmation using an alert dialog with 'Yes' and 'No' options. If the user selects 'Yes', it clears the specified fields in the form: Employee ID, Employee Name, Gender, Email ID, Department, and Address fields, which are located in certain cells of the spreadsheet. It also resets the background color of these cells to white.

The editRecord function maintains data integrity by ensuring that the user confirms the intention to edit through an alert dialog. It iterates through the database entries to find a matching record based on the search criteria. Once a match is found, it updates the record with new data entered in the form fields. It logs the current date and email of the editing user, ensuring accountability. The function also alerts the user of a successful update and clears the form fields to prevent unintended data use.

The submitData function first checks for user confirmation with an alert dialog. If the response is affirmative, it validates the entry using the validateEntry function. Post-validation, it identifies the next available blank row in the Database sheet and proceeds to transfer the data from the User Form fields to this row. It records values such as Employee ID, Name, Gender, Email ID, Department, and Address, along with the current date and the email of the person running the script. Finally, it clears the fields in the form, readying it for new entries.

You might also like