Search code examples
formsgoogle-apps-scriptgoogle-sheetsgoogle-forms

Shutdown Google Forms at given dates of the month and Open the form again at given dates of the month


Sorry for the newbie question. I have a google form that I open on the first day of each month and then shutdown on the 21st of the month. So basically users can only use the form the first 21 days of the month. I was wondering if there is a way to programmatically do this via a script. I know that this could be done via an add-on to the form but, I don't want to use an add-on as I don't what the code is doing in these and I want to make sure that the data is kept secure within the form sheet. Sorry for not having any code to demonstrate but have been doing a bit of research and can not seem to find anything remotely close this. Is it not possible to do this via Appscript? Thank you all in advance for your help.


Solution

  • I was able to do this us using a trigger and a script, named my form "Play"

    enter image description here

    Here is the script:

    function limitDays() {
      var form = FormApp.getActiveForm();
      var lastDay = 21;
      var currDate = new Date();
      var dayOfMonth = currDate.getDate();
      if (dayOfMonth > lastDay) {
        form.setAcceptingResponses(false);
      } else {
        form.setAcceptingResponses(true);
      }
    }