I\'ve found someone adding \"Invite Me\" link in the Google Calendar as shown below. I\'ve tried my best but could not find a way to add this link when someone clicks on an
Try to use "setAnyoneCanAddSelf(anyoneCanAddSelf)"
https://developers.google.com/apps-script/reference/calendar/calendar-event?hl=es#setAnyoneCanAddSelf(Boolean)
Molk is correct, you will need to setAnyoneCanAddSelf(true).
How I would go about it is deploying a script as a web app that takes a query parameter for the calendar event id, the Session.getActiveUser().getEmail(), and add them to the calendar event. I would create the URL in the primary calendar's Description field (like your screenshot, with the url to the deployed script url and adding the query parameter for the id.
An example would look something like this:
var calId = 'yourdomain.com_459nd7pqmn5irsqgn8p91febe4@group.calendar.google.com';
function inviteMe(){
try{
var cal = CalendarApp.getCalendarById(calId);
var start = new Date();
var end = new Date();
start.setHours(13);
end.setHours(14);
var event = cal.createEvent("Add Me Test", start,end);
event.setAnyoneCanAddSelf(true);
var eventId = event.getId();
var urlString = '<a href="' + ScriptApp.getService().getUrl() +'?eId=' + eventId + '" target="_blank">Invite Me</a>';
var desc ='Event details';
desc += '\n\n' + urlString;
// now that we have the url built out, add the description
event.setDescription(desc);
}catch(err){
Logger.log(err.lineNumber + ' - ' + err);
;
}
}
function doGet(event){
try{
// shorten the event parameter path;
var param = event.parameter;
// get the calendar event id passed in the query parameter
var eventId = param.eId;
var cal = CalendarApp.getCalendarById(calId);
var guest = Session.getActiveUser().getEmail();
var event = cal.getEventSeriesById(eventId);
event.addGuest(guest);
return ContentService.createTextOutput("You have been added to the event: " + event.getTitle());
}catch(err){
Logger.log(err.lineNumber + ' - ' + err);
}
}
And how it would look would be something like this: In the event details, click the invite me link
Once Processed, use ContentService to display a notice.
And finally see the calendar in the users calendar
The event owner will not see the link in their description area, only the raw html anchor text (see screenshot below). Google Calendar renders the link for everyone else; I assume for ease of editing, since the description field is just a textarea input, with no WYSIWYG controls.