2
votes

I have two forms linked with one spreadsheet, one sheet for each form. When I run such script

function myFunction() {
  var ss;
  ss = SpreadsheetApp.getActive();
  Logger.log(ss.getFormUrl());
}

I will see only one url (as life shows url for the second form). Is there any way to get urls for all linked forms?

2
There is a way to do this using DriveApp: see my answer hereuser3717023
Since August 2017, this is available through the 'sheet' object: sheet.getFormURL()beano

2 Answers

1
votes

This functionality is currently missing in the API. There is an existing request on the issue tracker for this here. Star that issue to follow it for the resolution.

0
votes

I know that it's an old question, but I'll still add an answer to whom it may concern.

Generally speaking, Form is connected to Sheet, not to Spreadsheet itself. So, one way to get all of the Spreadsheet forms is to go through the Sheets of the Spreadsheets, and get their Form URL, like that:

function getFormsOfSpreadsheet(spreadsheetId) {
  const ss = SpreadsheetApp.openById(spreadsheetId);
  const sheets = ss.getSheets();
  const formsUrls = [];

  for (const sheet of sheets) {
    const formUrl = sheet.getFormUrl();
    // getFormUrl() returns null if no form connected
    if (formUrl) {
      formsUrls.push(formUrl);
    }
  }
  
  return formsUrls;
}

Docs

The other possible way is to get all of the Forms in the Drive or in the Folder, iterate through them to get their destination and compare it to your Spreadsheet ID, like in this answer