Google Apps Script Code TheDataLabs
Google Apps Script Code TheDataLabs
function clearForm()
{
var myGoogleSheet= SpreadsheetApp.getActiveSpreadsheet(); //declare
a variable and set with active google sheet
var shUserForm = myGoogleSheet.getSheetByName("User Form");
//declare a variable and set with the User Form worksheet
// 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 = ui.alert("Reset Confirmation", 'Do you want to reset
this form?',ui.ButtonSet.YES_NO);
// Checking the user response and proceed with clearing the form if
user selects Yes
if (response == ui.Button.YES)
{
shUserForm.getRange("C4").setBackground('#FFFFFF');
shUserForm.getRange("C7").setBackground('#FFFFFF');
shUserForm.getRange("C9").setBackground('#FFFFFF');
shUserForm.getRange("C11").setBackground('#FFFFFF');
shUserForm.getRange("C13").setBackground('#FFFFFF');
shUserForm.getRange("C15").setBackground('#FFFFFF');
shUserForm.getRange("C17").setBackground('#FFFFFF');
return true ;
}
}
// Function to submit the data to Database sheet
function submitData() {
// 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 = ui.alert("Submit", 'Do you want to submit the
data?',ui.ButtonSet.YES_NO);
// Checking the user response and proceed with clearing the form if
user selects Yes
if (response == ui.Button.NO)
{return;//exit from this function
}
datasheet.getRange(blankRow,
1).setValue(shUserForm.getRange("C7").getValue()); //Employee ID
datasheet.getRange(blankRow,
2).setValue(shUserForm.getRange("C9").getValue()); //Employee Name
datasheet.getRange(blankRow,
3).setValue(shUserForm.getRange("C11").getValue()); //Gender
datasheet.getRange(blankRow,
4).setValue(shUserForm.getRange("C13").getValue()); // Email ID
datasheet.getRange(blankRow,
5).setValue(shUserForm.getRange("C15").getValue()); //Department
datasheet.getRange(blankRow,
6).setValue(shUserForm.getRange("C17").getValue());// Address
//get the email address of the person running the script and update
as Submitted By
datasheet.getRange(blankRow,
8).setValue(Session.getActiveUser().getEmail()); //Submitted By
shUserForm.getRange("C7").clear();
shUserForm.getRange("C9").clear();
shUserForm.getRange("C11").clear();
shUserForm.getRange("C13").clear();
shUserForm.getRange("C15").clear();
shUserForm.getRange("C17").clear();
}
}
function searchRecord() {
shUserForm.getRange("C7").setValue(rowValue[0]) ;
shUserForm.getRange("C9").setValue(rowValue[1]);
shUserForm.getRange("C11").setValue(rowValue[2]);
shUserForm.getRange("C13").setValue(rowValue[3]);
shUserForm.getRange("C15").setValue(rowValue[4]);
shUserForm.getRange("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 = SpreadsheetApp.getUi();
ui.alert("No record found!");
}
function deleteRow() {
// 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 = ui.alert("Submit", 'Do you want to delete the
record?',ui.ButtonSet.YES_NO);
// Checking the user response and proceed with clearing the form if
user selects Yes
if (response == ui.Button.NO)
{return;//exit from this function
}
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 = SpreadsheetApp.getUi();
ui.alert("No record found!");
}
function editRecord() {
// 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 = ui.alert("Submit", 'Do you want to edit the
data?',ui.ButtonSet.YES_NO);
// Checking the user response and proceed with clearing the form if
user selects Yes
if (response == ui.Button.NO)
{return;//exit from this function
}
datasheet.getRange(iRow,
1).setValue(shUserForm.getRange("C7").getValue()); //Employee ID
datasheet.getRange(iRow,
2).setValue(shUserForm.getRange("C9").getValue()); //Employee Name
datasheet.getRange(iRow,
3).setValue(shUserForm.getRange("C11").getValue()); //Gender
datasheet.getRange(iRow,
4).setValue(shUserForm.getRange("C13").getValue()); // Email ID
datasheet.getRange(iRow,
5).setValue(shUserForm.getRange("C15").getValue()); //Department
datasheet.getRange(iRow,
6).setValue(shUserForm.getRange("C17").getValue());// Address
//get the email address of the person running the script and update
as Submitted By
datasheet.getRange(iRow,
8).setValue(Session.getActiveUser().getEmail()); //Submitted By
shUserForm.getRange("C4").clear();
shUserForm.getRange("C7").clear();
shUserForm.getRange("C9").clear();
shUserForm.getRange("C11").clear();
shUserForm.getRange("C13").clear();
shUserForm.getRange("C15").clear();
shUserForm.getRange("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 = SpreadsheetApp.getUi();
ui.alert("No record found!");
}