You need an onFormSubmit function along with the
installable trigger.
If you are using a Html Service Form, you can get
the name of the destination sheet from the form event
output. You can't do that with forms created from
the spreadsheet. The best I have been able to do is
to compare the event timestamp to the timestamps on
the last rows of the form response sheets to determine which
sheet was updated. This is not totally fool proof since
it is possible for mulitiple forms to be submitted at
the same time (but not likely).
Try this:
//installable trigger also needed.
function onFormSubmit(e){
var ts=e.namedValues.Timestamp
findResponseForm(ts)
}
function findResponseForm(ts) {
var ss=SpreadsheetApp.getActiveSpreadsheet()
var s=ss.getSheetByName('Form Responses 1') //get 'Form Responses 1' sheet
var lr=s.getLastRow() //get last row number of 'Form Responses 1' sheet
var s1=ss.getSheetByName('Form Responses 2') //get 'Form Responses 2' sheet
var lr1=s1.getLastRow() //get last row number of 'Form Responses 2' sheet
var time1=s.getRange(lr, 1, 1,1).getValue() //get 'Form Responses 1'last Timestamp
var ftime1=Utilities.formatDate(time1, "GMT-6", "d/M/yyyy' 'HH:mm:ss") //convert 'Form Responses 1'last Timestamp format to form Timestamp format
var time2=s1.getRange(lr1, 1, 1,1).getValue() //get 'Form Responses 2'last Timestamp
var ftime2=Utilities.formatDate(time2, "GMT-6", "d/M/yyyy' 'HH:mm:ss") //convert 'Form Responses 1'last Timestamp format to form Timestamp format
if(ts==ftime1){ //if date/time match
Logger.log('Form Responses 1')
//call function to prosses 'Form Responses 1' data
}
else if(ts==ftime2){ //if date/time match
Logger.log('Form Responses 2')
//call function to prosses 'Form Responses 2' data
//Add more 'else if' if more forms are involved.
}
}