Search code examples
google-apps-scriptgoogle-forms

Get a list/array of all Google Forms


Google Apps Script gives you the ability to get reference to a form by its id or by its URL.

https://developers.google.com/apps-script/reference/forms/form-app

I want to iterate through all forms that have a certain string in its name.

I want to avoid having to maintain a list of all the form IDs as I go along. Forms come and go, and so I'd rather find all, and iterate on them.

I've tried looking through all the docs on the Google Apps Script site, and cannot find a list method of any kind.

How can I get a list of all the forms available?


Solution

  • Or you could do it the easier way:

    function allFormFilesWithStringInTitle() {
     // Log the name of every file in the user's Drive that is a form mime type
     // whose name contains "Untitled".
     //var files = DriveApp.searchFiles('title contains "Untitled"');
     var files = DriveApp.searchFiles('mimeType = "application/vnd.google-apps.form" and title contains "Untitled"');
    
     while (files.hasNext()) {
       var file = files.next();
       Logger.log(file.getName());
       Logger.log(file.getMimeType());
     }
    }