-
Notifications
You must be signed in to change notification settings - Fork 0
/
Limit.js
28 lines (24 loc) · 949 Bytes
/
Limit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Code to disable the form if we go over the amount of cider
* help from: https://stackoverflow.com/questions/48886503/how-to-limit-google-form-submissions-based-on-total-number-of-answers-not-number
* by Cayden Wright
* 9/4/2023
*/
function LimitCider() {
//open form and sheet
var form = FormApp.getActiveForm();
var ss = SpreadsheetApp.openById("SHEET_ID");
var sheet = ss.getSheetByName("Backend");
//get limit
sheet.setCurrentCell(sheet.getRange("A3"));
var cell = sheet.getCurrentCell();
var limit = cell.getValue();
//get remaining
sheet.setCurrentCell(sheet.getRange("A2"));
cell = sheet.getCurrentCell();
var remaining = cell.getValue();
if(remaining<=0){
form.setAcceptingResponses(false);
form.setCustomClosedFormMessage("Unfortunately, all "+limit+" gallons of cider have been reserved.\nYou are still welcome to stop by to see if we have any extra!")
}
}