0

good day!

I was able to create different calendar events using googlesheets thanks as well to our community. However, I now want to put a hyperlink of that created event in a column next to my calendar details. I've as well read about the same problem here, but can't seem to follow it. I'm pretty confused by what the answer meant as "For given event object of type CalendarEvent and given calendarId".

In my code, I though the event was inviteID = eventCal.getEventById(calendarId).split('@') while the calendarId is calendarId = Session.getActiveUser().getEmail(). However, when I now encode them with base64, the eventID generated doesn't match the generated one in my calendar. I've tried out several iterations but still to no avail.

Please check out my code below (I've only included the lines which I think are relevant for easier reading):

    function sendInvites(){
  var sheet = SpreadsheetApp.getActiveSheet();
  var calendarId = Session.getActiveUser().getEmail();
  var eventCal = CalendarApp.getCalendarById(calendarId);
      eventCal.createEvent(title, sDateTime, eDateTime, details);
      var inviteID = eventCal.getEventById(calendarId).split('@');
      var inviteURL = "https://calendar.google.com/calendar/r/eventedit/" + Utilities.base64Encode(inviteID[0]+""+calendarId);
      sheet.getRange(startrow + x, 26).setValue('=HYPERLINK("' + inviteURL + '","View")');
      }

My suspicion is that I'm not correctly extracting the eventID or calendarId. I hope for your guidance on this.

Thanks!

J.Mapz
  • 511
  • 2
  • 12
  • The post that you mentioned was from 2015. Have you read [How do I construct a link to a Google Calendar event?](https://stackoverflow.com/a/53928045/1330560) – Tedinoz Nov 19 '19 at 10:10
  • Hi @Tedinoz, yes I've read this one. But from what I understood, I have to manually open the event in my calendar and get its ID, and as well manually get my calendar ID. Or was I wrong on this assumption? – J.Mapz Nov 19 '19 at 10:14
  • How did you propose to find the eventid otherwise? – Tedinoz Nov 19 '19 at 10:27
  • @J.Mapz I have posted an answer modifying your code so that it properly creates the URL... However, I am unsure as to whether the URL will work as an "invite" URL or not... – carlesgg97 Nov 19 '19 at 10:32
  • @Tedinoz, I believe I just lack the understanding of the concepts in programming. Pretty new to this. – J.Mapz Nov 19 '19 at 11:31

1 Answers1

1

You get the event id from the event object returned by the createEvent() method call. I have corrected your code so that it actually gets the proper identifier to use with the eventedit URL:

function sendInvites(){
  var sheet = SpreadsheetApp.getActiveSheet();
  var calendarId = Session.getActiveUser().getEmail();
  var calendar = CalendarApp.getCalendarById(calendarId);
  var event = calendar.createEvent(title, sDateTime, eDateTime, details);
  var inviteID = Utilities.base64Encode(event.getId().split("@")[0] + " " + calendarId);
  var inviteURL = "https://calendar.google.com/calendar/r/eventedit/" + inviteID;
  sheet.getRange(startrow + x, 26).setValue('=HYPERLINK("' + inviteURL + '","View")');
}
carlesgg97
  • 4,184
  • 1
  • 8
  • 24
  • Thanks for this! After a few modification following your route, it worked! :) – J.Mapz Nov 19 '19 at 11:27
  • 1
    @J.Mapz Glad to hear!! If you think the modifications you made to my answer are relevant to your original question, please consider sharing them so anyone who finds this question can see the resolution. Thanks a lot – carlesgg97 Nov 19 '19 at 11:29
  • @J.Mapz Please share you mods if they are relevant. It may help others in the future. – Tedinoz Nov 19 '19 at 11:37