Copies of a master Google Form are emailed to groups. When a member of each group completes the form, the response is sent to a sheet in a Google Spreadsheet. If there are 10 groups, there would be 10 sheets in the spreadsheet.
The name of each sheet would default to Form Responses 1, Form Responses 2, Form Responses 3... etc.
How to change the Form Response sheet name to the name of the group.
Here is what I have attempted.
var form = FormApp.openById(copyForm.getId());
var formLink = form.getPublishedUrl();
var masterSpreadsheet = SpreadsheetApp.openById("ID");
form.setDestination(FormApp.DestinationType.SPREADSHEET, masterSpreadsheet.getId());
var sheets = masterSpreadsheet.getSheets();
for(var i = 0; i < sheets.length; i++) {
if(sheets[i].getFormUrl() == formLink) {
sheets[i].setName("Group Name");
}
}
It's renaming the sheet before the newly added sheet in the spreadsheet.
Thanks in advance.