Members-only tutorial

Watch the video and get the practice sheet with membership.

See membership options

Form Automations: Close Multiple Forms When Over Limit

About this Tutorial

Adding to the Form Automations:
Allow User to Reopen form without Apps Script access
Set Limit in a Sheet, not in Apps Script
Set Limits for different Forms

Video Transcript

<div>00:00 So, in a previous video, we've created a automation in forms Learn about forms and how to manage responses effectively. Opens in new tab which closes the form when you have a certain number Understand how to work with numbers in your sheets. Opens in new tab of responses.<br>00:12 And I want to add some more advanced features, such as, if we, as a creator of a sheet, create this automation, and there's another user, the user of the sheet, or even ourselves later on, we don't have, we don't want to re-open Apps Script Explore Google Apps Script for automating tasks. Opens in new tab to turn on the form again, to allow more people.<br>00:35 Say, you have a certain number Understand how to work with numbers in your sheets. Opens in new tab of attendees, but you want to, uh, open it again for one or two more.<br>00:42 Also, if we're building this automation, we don't want to have to go into the Apps Script Explore Google Apps Script for automating tasks. Opens in new tab again.

To have this number Understand how to work with numbers in your sheets. Opens in new tab change.<br>00:50 So, I'm going to put a limit Discover how to set limits in your queries. Opens in new tab somewhere in the sheet, and then, if I ever want to change that limit Discover how to set limits in your queries. Opens in new tab , I do not have to go into the Apps Script Explore Google Apps Script for automating tasks. Opens in new tab and change it.<br>00:57 Also, we're going to create multiple forms Learn about forms and how to manage responses effectively. Opens in new tab that link to the same sheet. How do we set limits for those different forms Learn about forms and how to manage responses effectively. Opens in new tab ?<br>01:05 So, that's what I'm going to go over in this video and work through. So, let's create the re-open the form, or re-open the, uh, allow responses.<br>01:16 So, what we're going to do is we need a unopen, so we're going to, unopen menu.

So, we're going to go to bettersheets.co slash snippets and get that code.<br>01:24 It's a very simple code here. Function Get to know functions and how they enhance your sheets. Opens in new tab on open. We're going to go add that at the top. And the menu We're going to call, Automations. Or actually, Apps Script Explore Google Apps Script for automating tasks. Opens in new tab menu.<br>01:40 You can type anything you want here. This text is going to be a different menu. And we're going to create a function Get to know functions and how they enhance your sheets. Opens in new tab , open responses.<br>01:50 And this will take this form that we have. So, we're just going to get the same form URL Learn about the different types of form URLs. Opens in new tab . We're going to get that form.<br>02:00 Form.setAcceptingResponses to true. That's it.

It's just going to open responses. Let's format Master formatting techniques for better sheet presentation. Opens in new tab document, save.<br>02:12 This open responses is going to be here. And we're going to say re-openResponses. Save. We don't need a second item. Save it again.<br>02:29 Now this on open will happen when we close our Apps Script Explore Google Apps Script for automating tasks. Opens in new tab and we re-open the sheet itself. So let's do that.<br>02:36 And next to help we'll have a menu. Here we can actually make it, there, there it is. Apps Script Explore Google Apps Script for automating tasks. Opens in new tab menu, re-openResponses. EditForm. I think it's closed right now.<br>02:52 This form is not accepting responses.

And let's go up to the Apps Script Explore Google Apps Script for automating tasks. Opens in new tab menu and re-openResponses. We do have to authorize it the first time we run it, probably because we added FormApp, I think. Allow. Let's go and just re-open again and see.<br>03:20 I think it's accepting responses, yeah. So now if we fill one out, let's go and fill one out. One more name, and I think it will close.<br>03:37 Let's close again after one. Let's refresh it, and let's see if it closed. Might have, oh, it only has one response, so it actually cleared out the past responses from that form.<br>04:01 Let's add another one.

One more, and I think we need to submit one more. A third? Or more. More than three.<br>04:11 Submit one more. Is this it? Let's go see if that, uh, maybe the trigger Understand triggers and how they automate actions. Opens in new tab is not created in this one.<br>04:32 Oh, I don't think we have the trigger Understand triggers and how they automate actions. Opens in new tab in this sheet yet. Yeah, so we've had to add this trigger Understand triggers and how they automate actions. Opens in new tab . That's what we're missing in this, oh, uh, check form.<br>04:45 In the past video we ended on this, that we already had the trigger Understand triggers and how they automate actions. Opens in new tab done. So, we need to create that trigger Understand triggers and how they automate actions. Opens in new tab again.<br>04:52 Now the trigger Understand triggers and how they automate actions. Opens in new tab is there, so let's get one more name with trigger Understand triggers and how they automate actions. Opens in new tab . Yay! Let's see how fast that happens.

Is it executing?<br>05:05 If we want to submit another response. This form is no longer accepting responses. Great! Now let's go check reopen responses.<br>05:13 Let's refresh. Now we can take more responses. Great!<br>05:25 So, that is the first one is now we have a, the user is able to open access again. Let's set the limit Discover how to set limits in your queries. Opens in new tab in the sheet, not in a, in the Apps Script Explore Google Apps Script for automating tasks. Opens in new tab .<br>05:37 So, if we have this sheet that we're on called Settings, let's say, and we say, Limit Discover how to set limits in your queries. Opens in new tab Form Responses, put a number Understand how to work with numbers in your sheets. Opens in new tab here, let's say 2.

In this cell, B10, we need to get the number Understand how to work with numbers in your sheets. Opens in new tab from there.<br>05:55 So, let's go to our editor Navigate the editor for efficient script management. Opens in new tab and change that. Right now, our response count and I'll see you in the editor Navigate the editor for efficient script management. Opens in new tab , is greater than or greater than 3. So, we'll call this Limit Discover how to set limits in your queries. Opens in new tab .<br>06:06 We'll actually say greater than or equal to Limit Discover how to set limits in your queries. Opens in new tab . So, it's not more. Variable Limit Discover how to set limits in your queries. Opens in new tab equals SpreadsheetApp Explore the SpreadsheetApp for sheet manipulations. Opens in new tab .get getactivespreadsheet.getSheetByName, the name is settings, getRange Learn how to retrieve specific ranges in your sheets. Opens in new tab is b10. Let's double check that that's correct, b10, yes, onSettings, and getValue.<br>06:31 getValue means we'll get the value inside that cell. Let's save it.

And now our limit Discover how to set limits in your queries. Opens in new tab is 2. I think our form is open, so we need to put in two names.<br>06:48 Norm. Submit another response. Franco. Submit. And now we're no longer accepting responses. Cool. All that has happened. We have now set a limit Discover how to set limits in your queries. Opens in new tab in the sheet.<br>07:02 But let's say we want to set limits for different forms Learn about forms and how to manage responses effectively. Opens in new tab . Let's go create a new form and connect it to our sheet, form.new. Second event.<br>07:21 Just want a name. In our responses, we'll link to sheets. We'll select Understand the select clause in queries. Opens in new tab an existing sheet. I think it'll be this one.<br>07:35 Let's go back to our sheet. There it is.

So we have Form Responses 1, Form Responses 2. So our first one is Form Responses 1. Our second one is Form Responses 2. And when sheets are coming, uh, when form is being submitted, we're using this checkForm function Get to know functions and how they enhance your sheets. Opens in new tab .<br>07:55 We're gonna add an e. This e gives us really interesting information. It's an event. We'll say variable URL equals e. range Get familiar with ranges and their applications. Opens in new tab .getSheet I think that's it.

So this URL, logger.log URL, is different for these two different sheets.<br>08:35 So let's go and get those URLs, and then we will set ifs, because we need to get the value from a different place.<br>08:48 So let's go to our settings and see. Let's say form 1 and form 2, we want, let's say, a limit Discover how to set limits in your queries. Opens in new tab of 4 on form 2, and a limit Discover how to set limits in your queries. Opens in new tab of 2 on form 1, or 20, or 50, or 100, doesn't matter the number Understand how to work with numbers in your sheets. Opens in new tab here.<br>09:02 But form 1 is going to be 10, and form 2 is going to be 11. So we'll log the URL.<br>09:12 that URL will probably be somewhere.

It's similar to something like this up here, but let's just double-check. I think this is our second event.<br>09:22 Yep, publish Learn how to publish your sheets effectively. Opens in new tab it. Then you want the link. Done. Again, let's copy this link. And say, Carl, submit.<br>09:44 And in our executions, this is our latest one, the URL. False.<br>09:56 There is our URL. So this is 1GARV, and actually, it is very different from this form URL Learn about the different types of form URLs. Opens in new tab .<br>10:13 Oh, this is it. 1GAR. So, the URL is not the shared URL you're sharing Understand sharing options for your sheets. Opens in new tab with people, but it's a URL of the form itself.<br>10:24 Right here. Let's double check that that is correct.

That is just with view form on the end. So we'll take that URL.<br>10:37 And now we can, so, check here, let's say, we'll put this in here, we'll say, variable form 1 or 2. 2, actually, equals this URL, and variable form 1 equals, we need to go back and get this, instead of closed form, view form.<br>11:06 So now we have our two separate URLs. So if URL is equal to form to we'll do something here, this limit Discover how to set limits in your queries. Opens in new tab , and we're going to do something different if the form is 1. So actually, I think 1 is B10 and 2 is B11.

There we go.<br>11:35 So now we have our form checker is getting the URL of the submitted form, checking which one, looking at the limit Discover how to set limits in your queries. Opens in new tab , and then saying if that limit Discover how to set limits in your queries. Opens in new tab is, if our response count is greater than or equal to the limit Discover how to set limits in your queries. Opens in new tab , let's close those.<br>11:52 And let's also change this open responses so that we open our different forms Learn about forms and how to manage responses effectively. Opens in new tab .

So we'll say open responses, open responses form one, and we'll create a whole nother function Get to know functions and how they enhance your sheets. Opens in new tab for open responses two.<br>12:08 So form two is this, so instead of URL getting it automatically, we're going to select Understand the select clause in queries. Opens in new tab it very specifically.<br>12:21 And there we go. We have Form 1 and Form 2. And we can add another item up here for our menu.<br>12:31 Reopen Form 2. Reopen Form 1. Let me just make sure we're calling the correct form number Understand how to work with numbers in your sheets. Opens in new tab here.<br>12:47 Great. Let's close this. Refresh our sheet. And now, next to Help, we have two items.<br>12:59 Let's reopen both.

Oh, the ID is going to be different, I think. Let's look back at our extension Apps Script Explore Google Apps Script for automating tasks. Opens in new tab and see what happened.<br>13:10 We might, I don't think we need this View Form.<br>13:25 Let's try that. So what the issue was, was this, I needed the edit URL, so just went to the sheet itself, or sorry, the form itself to edit and got the edit URL.<br>13:56 We're going to turn on, actually we don't need to do that. We can go to item. Our sheet and now try it.<br>14:08 So we finished script. It has reopened the form. We can go to tools, manage form, edit form and see if it is taking.<br>14:21 Perfect.

It's taking responses now. So now let's check if it's actually checking the correct one. If it's looking at this limit Discover how to set limits in your queries. Opens in new tab here, form one, it's going to be here.<br>14:36 Let's go and manage form. Go to live form. Let's fill in a couple. Andrew. Carl. It's continuing to let us set, but our form one was supposed to be.<br>15:03 Oh, I think our Apps Script Explore Google Apps Script for automating tasks. Opens in new tab then needs fixing here. Right, so we need to make sure that we're doing it to the right form.<br>15:24 So let's grab these. And instead of just the limit Discover how to set limits in your queries. Opens in new tab , we need to actually be setting the correct form.

I think it's this edit URL instead of this view form.<br>15:53 So form 1. This is form 1. And this is form 2. There we go.<br>16:13 So inside of our if function Get to know functions and how they enhance your sheets. Opens in new tab , we're getting the correct edit URL, and then we're editing the form responses, is accepting to false.<br>16:25 So let's do that again. Think 1, 2, once we put in one more Carl2, Frank again.<br>16:44 It's giving us an invalid argument Explore arguments and their role in functions. Opens in new tab URL. Let's Let's look at that on line 43. Seems like we just have the wrong URL here.<br>16:55 So let's put that in.

And we will try again.<br>17:08 And it worked.<br>17:20 It just took a minute before it showed up. I was clicking too fast. So now the form is closing correctly for the first one.<br>17:28 Let's look at the second one. Submit another response. This one has a limit Discover how to set limits in your queries. Opens in new tab . Let's change this to 2. And put in Andrew.<br>17:39 Let's see if that closed. And that already closed. Cool. So these are working now correctly. And here's a code.<br>17:54 Click down below for the code of these forms Learn about forms and how to manage responses effectively. Opens in new tab . It is a little tricky dealing with form URLs. And edit versus view form.<br>18:03 Bye.

But hopefully you can go and view this code and see what we're doing here so that we can set limits for different forms Learn about forms and how to manage responses effectively. Opens in new tab .</div>