1function getResponseSheetForGoogleForm() {
2 const formId = "<<Google Form Id>>";
3
4 // Open an existing Google Form by Id
5 const form = FormApp.openById(formId);
6
7 // Are the form responses stored in Google Sheets
8 const destinationType = form.getDestinationType();
9
10 if (destinationType !== FormApp.DestinationType.SPREADSHEET) {
11 Logger.log("This form is not saving responses in Google Sheets");
12 } else {
13 // Get the Id of the response spreadsheet
14 const destinationId = form.getDestinationId();
15
16 // Open the Google Workbook and iterate through each sheet
17 const formSpreadsheet = SpreadsheetApp.openById(destinationId);
18
19 const [formSheet] = formSpreadsheet.getSheets().filter((sheet) => {
20 // Returns the URL of the associated Google form
21 // that is sending its user responses to this sheet
22 const associatedFormUrl = sheet.getFormUrl();
23 return associatedFormUrl && associatedFormUrl.indexOf(formId) !== -1;
24 });
25
26 Logger.log(`The form responses are stored in ${formSheet.getName()}`);
27 }
28}