Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

create GCAL event when checkbox is ticked

170 views
Skip to first unread message

Jeremy Hu

unread,
Feb 24, 2025, 5:25:53 AMFeb 24
to Google Apps Script Community
Hi,

I would like to create GCAL event automatically when a checkbox is ticked. I'm currently facing this issue where it says the following below
Error
Error creating event: Specified permissions are not sufficient to perform the action. Required permissions: (https://www.googleapis.com/auth/calendar || https://www.googleapis.com/auth/calendar.readonly || https://www.google.com/calendar/feeds)

I'm verified that the calendar i'm referencing to is correct since a testCalendar function ran successfully.

Thank you for your help in adv

Screenshot 2025-02-24 at 12.36.16 PM.png
function onEdit(e) {
// Safety check for manual runs (exits if not triggered by an edit)
if (!e) {
console.log("No edit event detected. Exiting.");
return;
}

// Configuration (Match with your sheet and columns)
const CONFIG = {
sheetName: "Sales 2025", // Your sheet's name
titleColumn1: 7, // Column G (Title Part 1)
titleColumn2: 4, // Column D (Title Part 2)
dateColumn: 9, // Column I (Event Date)
checkboxColumn: 22, // Column V (Trigger Checkbox)
attendeeEmailColumn: 21 // Column U (Attendee Email)
};

// Get event details
const sheet = e.source.getActiveSheet();
const range = e.range;
const row = range.getRow();
const col = range.getColumn();

// Validate edit is on the correct sheet, column, and checkbox state
if (sheet.getName() !== CONFIG.sheetName ||
col !== CONFIG.checkboxColumn ||
e.value !== "TRUE") return;

// Retrieve data from the edited row
const dataRow = sheet.getRange(row, 1, 1, sheet.getLastColumn()).getValues()[0];
const title = `${dataRow[CONFIG.titleColumn1 - 1] || ""} - ${dataRow[CONFIG.titleColumn2 - 1] || ""}`.trim();
const attendeeEmail = dataRow[CONFIG.attendeeEmailColumn - 1]?.toString().trim();
const dateStr = dataRow[CONFIG.dateColumn - 1].toString().trim();

// Parse the date from "dd Mmm yyyy" format
function parseDate(dateStr) {
const [day, month, year] = dateStr.split(" ");
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
return new Date(year, months.indexOf(month), day);
}
const eventDate = parseDate(dateStr);

// Create calendar event with attendee
try {
const calendar = CalendarApp.getCalendarById("calendarIDremoved");
const event = calendar.createAllDayEvent(title, eventDate);

// Add attendee if email is present
if (attendeeEmail) {
event.addGuest(attendeeEmail);
}

// Uncheck the trigger box to prevent re-triggering
range.setValue(false);

// Debug log (check View > Logs in Apps Script editor)
console.log(`Event created: ${event.getTitle()} on ${eventDate}`);
if (attendeeEmail) {
console.log(`Attendee added: ${attendeeEmail}`);
} else {
console.log("No attendee email provided.");
}
} catch (error) {
console.error(`Error creating event: ${error.message}`);
}
}


Emerson Maia Paula

unread,
Feb 24, 2025, 5:31:35 AMFeb 24
to google-apps-sc...@googlegroups.com
You need to configure oauthScopres like this, and then give the necessary permissions, try this.
{
  "timeZone": "YOUR_TIME_ZONE",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/calendar",
    "https://www.googleapis.com/auth/spreadsheets"
  ]
}


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/1021833a-0441-4bd2-9a81-a2e0eb28e5afn%40googlegroups.com.

Jeremy Hu

unread,
Feb 24, 2025, 5:36:47 AMFeb 24
to Google Apps Script Community
i actually did this earlier but it didn't work as well.. 

changed onEdit to a time trigger and it works now

Reply all
Reply to author
Forward
0 new messages