Reputation: 748
I have a working script in one of my google sheets projects, but now I want it to be triggered when I hit the submit button on a Google Form I have. Basically, the data from my Google Form gets exported to my Sheets form, but then I have a script to analyze the data entered. For some reason, it seems like it's doing nothing when the onSubmitForm() function is triggered. It's clear there's a problem because my logger test line displays for the onSubmitForm function but not for the EvaluateResults function.
The code in my Google Form is simple:
function onSubmitForm(){
Logger.log("onSubmitForm Running");
a.EvaluateResults();
}
The code in the Google Sheets is simple as well:
function EvaluateResults(){
Logger.log("evaluation running");
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet_results = ss.getSheetByName("Sheet2");
var sheet_userForm = ss.getSheetByName("Form Responses 1");
sheet_results.getRange("C24").setValue((sheet_userForm.getRange("A2").getValue());
}
Upvotes: 0
Views: 3820
Reputation: 3355
You should write the entire function in Google form script itself. You can collect the response from Google form as soon as the submit is hit.
function onSubmitForm(e){
Logger.log("onSubmitForm Running");
var itemResponses = e.response.getItemResponses();
var emailAddress = itemResponses[1].getResponse(); // Response of second question
Logger.log(emailAddress)
var ss = SpreadsheetApp.openById("SS ID"); // Replace with your Spreadsheet Id
var sheet_results = ss.getSheetByName("Sheet2");
sheet_results.getRange("C24").setValue(emailAddress);
}
Upvotes: 4