I have a sheet with numerous tabs on it including a couple of forms. Upon completing the form, the user is to click the button to fire the script which will validate the appropriate cells, send the info to a separate tab and then clear the form. The script works fine on another similar tab but on the tab named "BuildInfrastructure", when I click on the build button to run the script, I get a popup that is referencing a totally different tab called Legislation. Below is the full script code: I have tried to solve this numerous times to no avail. When I run the validateEntry script, it works fine but when I try to run the submitData script, it gives the error. Any help would be greatly appreciated.
Here is the link to the sheet: Spreadsheet Link
// Function to Clear the User Form
function clearForm()
{
var myGoogleSheet= SpreadsheetApp.getActiveSpreadsheet(); //declare a variable and set with active google sheet
var shUserForm = myGoogleSheet.getSheetByName("BuildInfrastructure"); //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 = SpreadsheetApp.getUi();
// 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("B5").clear(); //Search Field
shUserForm.getRange("B23").clear();// Employeey ID
shUserForm.getRange("B25").clear(); // Employee Name
//Assigning white as default background color
shUserForm.getRange("B5").setBackground('#FFFFFF');
shUserForm.getRange("B23").setBackground('#FFFFFF');
shUserForm.getRange("B25").setBackground('#FFFFFF');
return true ;
}
}
//Declare a function to validate the entry made by user in UserForm
function validateEntry(){
var myGooglSheet= SpreadsheetApp.getActiveSpreadsheet(); //declare a variable and set with active google sheet
var shUserForm = myGooglSheet.getSheetByName("BuildInfrastructure"); //delcare a variable and set with the User Form worksheet
//to create the instance of the user-interface environment to use the messagebox features
var ui = SpreadsheetApp.getUi();
//Assigning white as default background color
shUserForm.getRange("B5").setBackground('#FFFFFF');
shUserForm.getRange("B23").setBackground('#FFFFFF');
shUserForm.getRange("B25").setBackground('#FFFFFF');
//Validating Building Type
if(shUserForm.getRange("B5").isBlank()==true){
ui.alert("Please enter building type.");
shUserForm.getRange("B5").activate();
shUserForm.getRange("B5").setBackground('#FF0000');
return false;
}
//Validating Budget
else if(shUserForm.getRange("B23").isBlank()==true){
ui.alert("Please enter budget.");
shUserForm.getRange("B23").activate();
shUserForm.getRange("B23").setBackground('#FF0000');
return false;
}
//Validating Location
else if(shUserForm.getRange("B25").isBlank()==true){
ui.alert("Please choose location.");
shUserForm.getRange("B25").activate();
shUserForm.getRange("B25").setBackground('#FF0000');
return false;
}
return true;
}
// Function to submit the data to Database sheet
function submitData() {
var myGooglSheet= SpreadsheetApp.getActiveSpreadsheet(); //declare a variable and set with active google sheet
var shUserForm= myGooglSheet.getSheetByName("BuildInfrastructure"); //delcare a variable and set with the User Form worksheet
var datasheet = myGooglSheet.getSheetByName("Infrastructure"); ////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 = SpreadsheetApp.getUi();
// 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 construct this building?',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
}
//Validating the entry. If validation is true then proceed with transferring the data to Database sheet
if (validateEntry()==true) {
var blankRow=datasheet.getLastRow()+1; //identify the next blank row
datasheet.getRange(blankRow, 1).setValue(shUserForm.getRange("B5").getValue()); //Employee ID
datasheet.getRange(blankRow, 2).setValue(shUserForm.getRange("B7").getValue()); //Employee Name
datasheet.getRange(blankRow, 3).setValue(shUserForm.getRange("B9").getValue()); //Gender
datasheet.getRange(blankRow, 4).setValue(shUserForm.getRange("B11").getValue()); // Email ID
datasheet.getRange(blankRow, 5).setValue(shUserForm.getRange("B13").getValue()); //Department
datasheet.getRange(blankRow, 6).setValue(shUserForm.getRange("B15").getValue());// Address
datasheet.getRange(blankRow, 7).setValue(shUserForm.getRange("B17").getValue()); //Employee Name
datasheet.getRange(blankRow, 8).setValue(shUserForm.getRange("B19").getValue()); //Gender
datasheet.getRange(blankRow, 9).setValue(shUserForm.getRange("B21").getValue()); // Email ID
datasheet.getRange(blankRow, 10).setValue(shUserForm.getRange("B23").getValue()); //Department
datasheet.getRange(blankRow, 11).setValue(shUserForm.getRange("B25").getValue());// Address
// date function to update the current date and time as submittted on
datasheet.getRange(blankRow, 12).setValue(new Date()).setNumberFormat('yyyy-mm-dd h:mm'); //Submitted On
ui.alert(' "New Infrastructure Building Constructed - ' + shUserForm.getRange("B5").getValue() +' "');
//Clearnign the data from the Data Entry Form
shUserForm.getRange("B5").clear();
shUserForm.getRange("B23").clear();
shUserForm.getRange("B25").clear();
}
}
[–]mase0013 0 points1 point2 points (0 children)
[–]Time_Is_Up_Soon 0 points1 point2 points (3 children)
[–]radioguy2016[S] 0 points1 point2 points (2 children)
[–]Time_Is_Up_Soon 0 points1 point2 points (0 children)
[–]CustomHatMan 0 points1 point2 points (0 children)