Google calendar event being created twice / duplicating

Here is a cut up snippet of the script with if statements and else. It appears to make the toast/popup come up twice in one second, indicating that it’s duplicating. Thoughts?



function create_event(e){

var index = e.range.getRow();
var make_event = sheet.getRange(index, 12); 


if (e.range.getColumn()==12 || e.range.getColumn()==10) {
  
 if (make_event.isChecked()==true){
 
   if (ssa.getSheetByName("Tracker").getRange(index, 13).isBlank()) {


      ss.toast("Invite created! Don't forget to attach the resume.", "Notice", 25);

      var today = new Date();
      var thirtyMinutes = new Date(today);
      thirtyMinutes.setMinutes(today.getMinutes()+30);

      var desc = "";
        
      var event = calendar.createEvent(event_title, today, thirtyMinutes, {description: desc}).setVisibility(CalendarApp.Visibility.PRIVATE).setColor("11").addPopupReminder(10);



      else {
            
      const viewInvite = sheet.getRange(index, 13).getFormula();
      const getEventId = viewInvite.match(/eventedit\/(\w+)/);
      
      if (getEventId && getEventId.length == 2) {
      const eventId = Utilities.newBlob(Utilities.base64Decode(getEventId[1])).getDataAsString().split(" ");

      const timeOfEvent = calendar.getEventById(eventId[0]).getStartTime();
      Logger.log(eventId[0]);
  
      isEventLinkBlank = interview_date.setValue(timeOfEvent);

            ss.toast("New date found and updated!", "Notice", 25);

      }
     }

}

function createOnEditTrigger(e) {
  var triggers = ScriptApp.getProjectTriggers();
  var shouldCreateTrigger = true;
  triggers.forEach(function (trigger) {
    
    if(trigger.getEventType() === ScriptApp.EventType.ON_EDIT && trigger.getHandlerFunction() === "create_event") {
      shouldCreateTrigger = false; 
    }
  });
  
  if(shouldCreateTrigger){
    ScriptApp.newTrigger("create_event").forSpreadsheet(SpreadsheetApp.getActive()).onEdit().create();
  }
}

Apologies in advance, I cut up the script so the brackets are inaccurate and there’s some missing pieces but I think the problem is comprised in what’s above

Leave a Comment