Reputation: 3
I want to know if there's the possibiliy to know when an event in google calendar is created, I just have found how to create an event and take its info to create another I want to send the info of the event to a spreadsheed or any document
I just got this..
function createEvent() {
var calendarId = 'primary';
var eventSeries = CalendarApp.getDefaultCalendar().createEventSeries('Evento de prueba',
new Date('December 20 2014 10:00:00 AM -6'),
new Date('December 20 2014 10:30:00 AM -6'),
CalendarApp.newRecurrence().addWeeklyRule().
onlyOnWeekdays([CalendarApp.Weekday.SATURDAY]),
{ location: 'Tacos'});
Logger.log('EventSeriesID: ' + eventSeries.getId());
if (eventSeries.getTitle() == 'Evento de prueba'){
var calendarId2 = 'primary';
var event = CalendarApp.createEvent(eventSeries.getTitle(), eventSeries.getDateCreated(), new Date(eventSeries.getDateCreated() + 2),
{location : eventSeries.getLocation()});
}
}
Upvotes: 0
Views: 545
Reputation: 583
I am not sure if you want this way or other way, but you can try for the following code.
function createEvent() {
try{
var calendarId = 'primary';
var eventSeries = CalendarApp.getDefaultCalendar().createEventSeries('My Events',
new Date('December 20 2014 12:00:00 PM'),
new Date('December 20 2014 03:30:00 PM'),
CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekdays([CalendarApp.Weekday.SATURDAY]),
{ location: 'Tacos'});
Logger.log('EventSeriesID: ' + eventSeries.getId());
if (eventSeries.getTitle() == 'My Events'){
var calendarId2 = 'primary';
var event = CalendarApp.createEvent(eventSeries.getTitle(), eventSeries.getDateCreated(), new Date(eventSeries.getDateCreated() + 2),
{location : eventSeries.getLocation()});
var ss_id = logEventData(event);
Logger.log(ss_id);
sendMail(ss_id);
}
}catch(error){
Logger.log(error.message);
}
}
function logEventData(event) {
var ss = SpreadsheetApp.create('calender-events-logs');
var eventDetails = [];
eventDetails.push(event.getTitle());
eventDetails.push(event.getDescription());
eventDetails.push(event.getCreators()[0]);
//You can get number of other details here if you want to.
ss.appendRow(eventDetails);
return ss.getId();
}
function sendMail(ss_id) {
var emailTo = 'Put your email id here';
var subject = 'Test';
var body = 'Test';
var pdf = DocsList.getFileById(ss_id).getAs('application/pdf').getBytes();
var attachment = {fileName:'CalendarEventLogs.pdf',content:pdf, mimeType:'application/pdf'};
// Send the freshly constructed email
MailApp.sendEmail(emailTo, subject, body, {attachments:[attachment]});
//MailApp.sendEmail(recipient, subject, body);
// Delete the dummy spreadsheet
deleteDummySheet(ss_id);
}
function deleteDummySheet(ss_id) {
DocsList.getFileById(ss_id).setTrashed(true);
}
Upvotes: 1