You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为填写Google表单的用户自动添加Google日历事件?

Great question! This is a really handy workflow, and you can implement it seamlessly using Google Apps Script—no third-party tools required. Let's walk through the steps clearly:

实现步骤

1. 准备你的表单与日历

  • First, make sure your Google Form includes all necessary fields for the calendar event: things like event title, start date/time, end date/time, attendee email, and location (if needed). These fields will map directly to the details of your calendar event.
  • Open your target Google Calendar, go to Settings and sharing → Integrate calendar, and copy the Calendar ID (it looks like an email address). You'll need this later.

2. Open the Form's Script Editor

  • Open your Google Form, click the Extensions menu at the top, then select Apps Script. This will launch a new tab with the Google Apps Script editor.
  • Delete the default myFunction() placeholder code—we'll replace it with our custom logic.

3. Write the Form Submit Trigger Script

Paste this code into the editor, then customize it to match your form's field names and calendar ID:

function onFormSubmit(e) {
  // Pull responses from the form submission
  const responses = e.response.getItemResponses();
  let eventTitle = "";
  let eventStart = new Date();
  let eventEnd = new Date();
  let attendeeEmail = "";
  let eventLocation = "";

  // Match responses to your form's field titles (update these to match your form!)
  for (const response of responses) {
    const fieldTitle = response.getItem().getTitle();
    const fieldValue = response.getResponse();

    switch(fieldTitle) {
      case "Event Title": // Replace with your form's actual event title field name
        eventTitle = fieldValue;
        break;
      case "Start Time": // Replace with your form's start date/time field name
        eventStart = new Date(fieldValue);
        break;
      case "End Time": // Replace with your form's end date/time field name
        eventEnd = new Date(fieldValue);
        break;
      case "Attendee Email": // Replace with your form's attendee email field name
        attendeeEmail = fieldValue;
        break;
      case "Location": // Optional: add if you have a location field
        eventLocation = fieldValue;
        break;
    }
  }

  // Access your target calendar (paste your Calendar ID here!)
  const calendarId = "your-calendar-id@group.calendar.google.com";
  const calendar = CalendarApp.getCalendarById(calendarId);

  // Create the calendar event
  const event = calendar.createEvent(
    eventTitle,
    eventStart,
    eventEnd,
    {
      location: eventLocation,
      guests: attendeeEmail,
      sendInvites: true // Set to false if you don't want to send invite emails
    }
  );

  // Optional: Log the event creation for debugging
  console.log(`Successfully created event: ${event.getTitle()} (ID: ${event.getId()})`);
}
  • Critical: Update the field titles in the switch statement to exactly match the titles in your Google Form (capitalization and spaces matter!). Also replace the calendarId with the one you copied earlier.

4. Set Up the Form Submit Trigger

  • In the Apps Script editor, click the Triggers icon (the alarm shape) on the left sidebar.
  • Click Add Trigger at the bottom right, then configure these settings:
    • Choose which function to run: onFormSubmit
    • Choose which deployment to run: Head
    • Select event source: From form
    • Select event type: On form submit
  • Click Save. You'll be prompted to authorize the script—follow the steps to grant access (since this is your own script, it's safe to bypass the "unverified app" warning by clicking Advanced → Go to [Script Name] (unsafe)).

5. Test the Workflow

  • Submit a test response in your Google Form.
  • Check your target Google Calendar—you should see a new event with all the details from your form submission.
  • If something goes wrong, check the Executions tab in the Apps Script editor to view error logs and debug issues.
注意事项
  • Make sure your form's date/time fields are set to the Date or Date and time type—this ensures the script can correctly parse the input into a Date object.
  • If you need to add multiple attendees, set your form's email field to accept multiple responses (separated by commas), then pass the entire string to the guests parameter.
  • You can extend the script to add event descriptions, set reminders, or even update existing events—check the Google Apps Script CalendarApp documentation for more options.

内容的提问来源于stack exchange,提问作者Dmytro Zorin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:24:27