1
votes

I have very limited experience with Google Apps Scripts, but have successfully modified the code from https://developers.google.com/apps-script/quickstart/forms to meet almost all of my needs.

Need to know how to view on my calendar all guests who sign up for a date.

I have investigated CalendarApp options, but can't get anything formatted to work so that the name of anyone who completes the Google Form for a specific date shows up on my calendar on that date -- maybe as a guest or attendee?

  var cal = CalendarApp.getOwnedCalendarById(XXX);
  for (var i = 1; i < values.length; i++) {
    var session = values[i];
    var title = session[0];
    var start = joinDateAndTime_(session[1], session[2]);
    var end = joinDateAndTime_(session[1], session[3]);
    var options = {location: session[4], sendInvites: true};
    var event = cal.createEvent(title, start, end, options)
        .setGuestsCanSeeGuests(false);  
    session[5] = event.getId();

  }
  range.setValues(values);

  var schedule = {};
  for (var i = 1; i < values.length; i++) {
    var session = values[i];
    var day = session[1].toLocaleDateString();
    var time = session[2].toLocaleTimeString();
    if (!schedule[day]) {
      schedule[day] = {};
    }
    if (!schedule[day][time]) {
      schedule[day][time] = [];
    }
    schedule[day][time].push(session[0]);
  }

  // Create the form and add a multiple-choice question for each timeslot.
  var form = FormApp.create('2019-2020 Semester 1 Sign up');
  form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
  form.addTextItem().setTitle('Name').setRequired(true);
  form.addTextItem().setTitle('Email').setRequired(true);
  form.addTextItem().setTitle('Phone Number').setRequired(false);
  for (var day in schedule) {
    var header = form.addSectionHeaderItem().setTitle('Odysseys on ' + day);
    for (var time in schedule[day]) {
      var item = form.addMultipleChoiceItem().setTitle(time + ' ' + day)
          .setChoiceValues(schedule[day][time]);
    }
  }
}
1
I know this isn't what you asked about, but if you make a scheduling calendar you can create "office hours" appointment blocks and people will sign up for portions of thoseJ. G.
When you say you can't get them to show up on your calendar, do you mean that when you click the event created on your calendar the guest's name isn't visible? Or do you mean that you want the guest name in the event title? If it's the latter, get the name provided and add it to e.g. var title = name + ": " + session[0]; ;sinaraheneba
alternatively, try including the guest within the parameters object of createEvent() or using addGuest()sinaraheneba
Thank you, @Altigraph for the clarifying questions. This describes my challenge: "when you click the event created on your calendar the guest's name isn't visible." I think either the addGuest() or createEvent(). Could you help me with the specific syntax? Where in the code is this included? I gather the guest names from a form created in a separate function.Tracy Ballinger

1 Answers

0
votes

I see you want to make sure your events have the right guests added to them. After reading the comments I can see that Altigraph put you on the right track. Below is the syntax you need (I’m assuming that “values” refers to a user’s particular response to the form):

For adding guests in the createEvent() options:

for (var i = 1; i < values.length; i++) {
    var session = values[i];
    var title = session[0];
    var start = joinDateAndTime_(session[1], session[2]);
    var end = joinDateAndTime_(session[1], session[3]);
    var options = {location: session[4], sendInvites: true, 
        guests: email,
    };
    var event = cal.createEvent(title, start, end, options)
    session[5] = event.getId();
  }

This email you can request from the user in the form, like you get their name or their phone, if you use a Google Form directly, there is the option to use this method to get the user’s email.

Alternatively, to use addGuest(), once you have the calendar created (i.e. the “event” object you have at the end of this snippet) you would simply use event.addGuest(email); where email is the same as in the other option. The documentation for it is at this link