Gabriel Crivelli
Gabriel Crivelli

Reputation: 105

Script generates new Google spreadsheets from template and name them upon form-submitted data

I'm trying to have this script working, but I'm missing something. It should grab data submitted via webform and stored in a spreadsheet that has this script attached, and then perform the following:

*create a new spreadsheet from a pre-formatted and ready-to-use template spreadsheet

*name the new spreadsheet with the data submitted via webform (eg. ID, date and else)

*also, the template as more than one sheet.

function CreateNewSS() {
var ss = SpreadsheetApp.getActiveSpreadsheet(); 
ss.copy("Prefix " + data());  //create the new spreadsheet. 
var data = Range.getCell(0, 0); 
var sheet = ss.getSheetByName('UserSubmittedData'); // sheet feed by web form 
var range = sheet.getRange(1,1); 
}

I'm stuck at this point.

Thanks in advance for any hint.

Upvotes: 0

Views: 1813

Answers (1)

Srik
Srik

Reputation: 7965

You should use the onFormSubmit event to handle this. See Understanding Events section of the documentation for details.

function onFormSubmit(e){

var resp = e.responses; 
var data = resp.getItemResponses()[0].getResponse().toString(); // Change 0 to the question number in the form
var ss = SpreadsheetApp.getActiveSpreadsheet(); 
ss.copy("Prefix " + data());  //create the new spreadsheet. 

}

Upvotes: 2

Related Questions