简体   繁体   English

如何知道是否使用GAS在Google日历中创建了活动?

[英]How to know if an event is created in Google Calendar with GAS?

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 我想知道是否有可能知道何时创建Google日历中的事件,我只是找到了如何创建事件并利用其信息来创建另一个事件,我想将该事件的信息发送到电子表格或任何文档

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()});
     }
}

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM