Advertisement
jakkyjack

Untitled

Jul 8th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Function to identify last row of sheet filled with formulas
  2. function getLastRowS(range){
  3.  var rowNum = 0;
  4.  var blank = false;
  5.  for(var row = 0; row < range.length; row++){
  6.    if(range[row][0] === "" && !blank){
  7.      rowNum = row;
  8.      blank = true;
  9.    }else if(range[row][0] !== ""){
  10.      blank = false;
  11.    };
  12.  };
  13.  return rowNum;
  14. };
  15.  
  16. // Function to submit the data to Database sheet
  17. function submitData() {
  18.    
  19.  var myGooglSheet = SpreadsheetApp.getActiveSpreadsheet(); //declare a variable and set with active google sheet
  20.  var shUserForm = myGooglSheet.getSheetByName("Data Entry Form"); //delcare a variable and set with the User Form worksheet
  21.  var datasheet = myGooglSheet.getSheetByName("ORDER_HEADERS"); ////delcare a variable and set with the Database worksheet
  22.  //to create the instance of the user-interface environment to use the messagebox features
  23.  var ui = SpreadsheetApp.getUi();
  24.   // Display a dialog box with a title, message, and "Yes" and "No" buttons. The user can also
  25.  // close the dialog by clicking the close button in its title bar.
  26.  var response = ui.alert("Submit", 'Do you want to submit the data?',ui.ButtonSet.YES_NO);
  27.  // Checking the user response and proceed with clearing the form if user selects Yes
  28.  if (response == ui.Button.NO)
  29.  {return;//exit from this function
  30.  }
  31.  //Validating the entry. If validation is true then proceed with transferring the data to Database sheet
  32. if (validateEntry()  == true) {
  33.     var SpecificCol = datasheet.getRange("A:A").getValues(); //selecting a specific column w/o formulas
  34.    var blankRow = getLastRowS(SpecificCol) + 1; //identify the next blank row
  35.    datasheet.getRange(blankRow, 1).setValue(shUserForm.getRange("D3").getValue()); //Order Number
  36.    datasheet.getRange(blankRow, 2).setValue(shUserForm.getRange("D5").getValue()); //Order Date
  37.    datasheet.getRange(blankRow, 3).setValue(shUserForm.getRange("D7").getValue()); //Expected Date
  38.    datasheet.getRange(blankRow, 4).setValue(shUserForm.getRange("D9").getValue()); //Order Type
  39.    datasheet.getRange(blankRow, 5).setValue(shUserForm.getRange("D11").getValue()); //Partner Name
  40.    
  41.    ui.alert(' "New Data Saved - Emp #' + shUserForm.getRange("D3").getValue() +' "');
  42.   //Clearnign the data from the Data Entry Form
  43.    shUserForm.getRange("D3").clear();
  44.    shUserForm.getRange("D5").clear();
  45.    shUserForm.getRange("D7").clear();
  46.    shUserForm.getRange("D9").clear();
  47.    shUserForm.getRange("D11").clear();    
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement