1
votes

I have two google separate forms that submit new client data to two separate spreadsheets. How would I use the onFormSubmit() on two separate spreadsheet sources in one app script editor? thank you all very much :D

if this is getting one sheet how could it implement two or more? i think i get SpreadsheetApp.getSheetByName('xyz'); and im a little unsure exactly what an active sheet is or activated I think it is the sheet you're currently on in the spreadsheet the dev app script is being derived from. I might be missing some other basic concepts

function onFormSubmit(){
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sht = ss.getSheetByName('New Client Submission Form (Phone)'&&'New Client Submission Form (Emailed)')
  var activeRng = sht.getRange("A2:K2")
  var values = activeRng.getValues()
  var height = values.length
  var width = values[0].length
  var ss_dest = SpreadsheetApp.openById('1wgzUSXFNLFQz6tv42Cp_o94qRPAB9IkZnKP5tGL003o')
  var sht_dest = ss_dest.getSheetByName('Estimate Compiler')
  var destRange = sht_dest.getRange(2,1,height,width)
  destRange.setValues(values)
  }

this function does exatly as expected I just don't know how to implement two or more yet

1
You can link multiple forms to the same spreadsheet and multiple tabs. Using the onFormSubmit event object e.range.getSheet() to determine which linked sheets they were going to and thus which form that they came from. - Cooper
So you could tell what form they came from with something like this: function onFormSubmit(e) { var formObj={LinkedSheet1:FormName1,LinkedSheet2:FormName2}; var form=formObj[e.range.getSheet().getName()]; } - Cooper

1 Answers

2
votes
function onFormSubmit(e) { 
  var formObj={LinkedSheet1:FormName1,LinkedSheet2:FormName2};//you provide this from a knowledge of the connection between the form and linked sheet 
  var form=formObj[e.range.getSheet().getName()];//this returns the form for each sheet
  switch (form) {
    case 'FormName1':
      //code for FormName1
      break;
    case 'FormName2':
      //code for FormName2
      break;
  }
}

onFormSubmit Event Object