I have script below to create calendar events from google form. The script working for now but I want to record its own eventid into that event description. Then when user want to delete their own event, they can refer into description and I will have another form for user to delete their own event using this eventid.
//var calendarId = "[email protected]";
var typeId = 2;
var nameId = 3;
var startDtId = 4;
var endDtId = 5;
var emailId = 6
var eventId = 7
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var lr = rows.getLastRow();
function getLatestAndSubmitToCalendar() {
var startDt = sheet.getRange(lr, startDtId, 1, 1).getValue();
var endDt = sheet.getRange(lr, endDtId, 1, 1).getValue();
var name = sheet.getRange(lr, nameId, 1, 1).getValue();
var email = sheet.getRange(lr, emailId, 1, 1).getValue();
var desc = "text here" "\n" "text here" "\n" "text here"; //<--possible to insert eventid here?
var title = sheet.getRange(lr, typeId, 1, 1).getValue() " " name;
//var type = sheet.getRange(lr, typeId, 1, 1).getValue();
createAllDayEvent(calendarId,title,startDt,endDt,desc,email);
}
function createAllDayEvent(calendarId, title, startDt, endDt, desc, email) {
var cal = CalendarApp.getCalendarById(calendarId);
var start = new Date(startDt);
var end = new Date(endDt);
end.setDate(end.getDate() 1);
var email = email;
var title = title;
//var type = type;
var event = cal.createAllDayEvent(title, start, end, {
description : desc,
guests: email
});
event.setGuestsCanModify(true);
var eventid = event.getId();
sheet.getRange(lr, eventId, 1, 1).setValue(eventid);
}
CodePudding user response:
I believe your goal is as follows.
- You want to add the event ID to the description when the event is created using your showing script.
In this case, how about the following modification?
From:
var eventid = event.getId();
To:
var eventid = event.getId();
event.setDescription(desc "\n" eventid);
In this modification, the event ID is added as a new line in the description. So, please modify \n
for your actual situation.
Or, if you want to put only the event ID, please modify as follows.
var eventid = event.getId();
event.setDescription(eventid);
Or, if you want to use the event ID using Calendar API, please use the event ID as var eventid = event.getId().split("@")[0];
.
- When this modification is reflected in your showing script, when the event is created, the event ID retrieved from the created event is put to the description.