Skip to content

Instantly share code, notes, and snippets.

@barrieroberts
Created October 21, 2017 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barrieroberts/88e9e9fd5a8835b2a4a6bedcf0a16c39 to your computer and use it in GitHub Desktop.
Save barrieroberts/88e9e9fd5a8835b2a4a6bedcf0a16c39 to your computer and use it in GitHub Desktop.
14c Appointment System
function meetingTimes() {
var form = FormApp.getActiveForm();
//Get current times on Form
var timesArray = [];
var questions = form.getItems();
var timeQ = questions[1].asMultipleChoiceItem();
var choices = timeQ.getChoices();
for (var i = 0; i < choices.length; i++) {
timesArray.push(choices[i].getValue());
}
//Get all form responses and the latest one
var formResponses = form.getResponses();
var latestFR = formResponses[form.getResponses().length-1];
//Get submitted time from form
var itemResponses = latestFR.getItemResponses();
var itemResponse = itemResponses[1];
var submittedTime = itemResponse.getResponse();
//Remove submittedTime from array
for (x in timesArray){
if(timesArray[x] === submittedTime) {
var indexT = timesArray.indexOf(submittedTime);
timesArray.splice(indexT, 1);
}
}
//Replace time question on form with array
timeQ.setChoiceValues(timesArray);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment