Update attendees when editing a Google calendar using Google script applications

Situation

I have a calendar with a lot of events on it (staff assessment).

I made changes (changing the length of the event, etc.), but invitations are sent to people who have a calendar of lotus notes (poor people).

Does this mean that if I do not call what will be called "Send Notification"? in the version of things with a mouse click, they have no way of knowing that the event has been updated.

( Similar to Q )

example of the update triggering

In this example, the event that I am trying to fire is the same as sending the update? modal is accepted with shipment.

the code

Here is an example of a code that receives all events on the calendar Appraisalsand changes its location to the "moon".

function fixInvitations(){
  //get the callendar named "Appraisals"
  var cApp = CalendarApp.getCalendarsByName("Appraisals")[0];
  var events = cApp.getEvents(new Date(), new Date("Dec 30 2014"));

  for (eIndex in events){
    var event = events[eIndex];
    event.setLocation("the moon");
  }
}

Question

, , ?

, , , Google, .

,

, , .ics ( ). VCALENDAR VEVENT. VEVENTs

UPDATE UID UID. , :

SEQUENCE:<Num of Update>

I.e., :

SEQUENCE:1

, .ics, , . , .

+4
4

ekoleda+devrel@google.com: , addGuest http://code.google.com/p/google-apps-script-issues/issues/detail?id=574

, :

, CalendarApp Advanced Calendar :

  •   
  • CalendarApp "@google.com" ex. b3gv... a5jrs@google.com  
  • /API , @google.com ex. b3gv... a5jrs  

:

function sendInvite(calendarId, eventId, email) {
  var event = Calendar.Events.get(calendarId, eventId);
  if(event.attendees) {
    event.attendees.push({
      email: email
    });
  } else {
    event.attendees = new Array({email: email});
  }
  event = Calendar.Events.patch(event, calendarId, eventId, {
    sendNotifications: true
  });
}

, - , , . , , , . , , , ( , gmail). , , - , . , - , .

+2

, : , , , , , , , script . calendarImport() . ( ) calendarCreateEvent, , . , , .

, . , onEdit. , script, , /if . , .

, , , , , , , , , , , - , , .

.

function calendarImport(){
  //http://www.google.com/google-d-s/scripts/class_calendar.html#getEvents
  // The code below will retrieve events between 2 dates for the user default calendar and
  // display the events the current spreadsheet
  var cal = CalendarApp.getDefaultCalendar();
  var calId = cal.getId();
  var sheet = SpreadsheetApp.getActiveSheet();
  var sheetName = SpreadsheetApp.getActiveSheet().setName(calId +" Calendar Data");
  var events = cal.getEvents(new Date("March 9, 2014"), new Date("March 14, 2014"));
  for (var i=0;i<events.length;i++) {
    //http://www.google.com/google-d-s/scripts/class_calendarevent.html
    Logger.log(events);
    var details=[[events[i].getId(),events[i].getTitle(), events[i].getDescription(), events[i].getStartTime(), events[i].getEndTime(),events[i].getLocation()]];
    var guestList = events[i].getGuestList();
    var guestArray = [];
    for (var n in guestList){
      var guestEmail = (guestList[n].getEmail());
      guestArray.push(guestEmail);
      Logger.log(guestArray);

    }

    var row=i+1;
    var range=sheet.getRange(row+1,1,1,6);
    range.setValues(details);
    var guestRange = sheet.getRange(row+1,7,1,1);
    guestRange.setValues([guestArray]);
    var dateAdded = Utilities.formatDate(new Date(), "GMT-6","MM/dd/yy HH:mm:ss");
    var dateAddedRange = sheet.getRange(row+1,8,1,1);
    dateAddedRange.setValue(dateAdded);
  }
}

function onEdit(event){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var calId = CalendarApp.getDefaultCalendar().getId();
  var sh = ss.getSheetByName(sheetName);
  var actSht = event.source.getActiveSheet();
  var actRng = event.source.getActiveRange();
  var index = actRng.getRowIndex();
  Logger.log(index);
  var dateCol = actSht.getLastColumn();
  var calId
  var lastCell = actSht.getRange(index,dateCol);
  var date = Utilities.formatDate(new Date(), "GMT-6", "MM/dd/yyyy HH:mm:ss");
  lastCell.setValue(date);
  var modifiedRow = sh.getRange(index,1,1,ss.getLastColumn()).getValues();
  Logger.log(modifiedRow[0][7])
  if (modifiedRow[0][7] < modifiedRow[0][8]){
    var firstAdded = modifiedRow[0][7];
    var dateModified = modifiedRow[0][8];
    calendarCreateEvent(index,firstAdded,dateModified,calId);
  }


}

function calendarCreateEvent(index,firstAdded,dateModified,calId){
  var sheet = SpreadsheetApp.getActiveSheet();
  var added = firstAdded;
  var modified = dateModified;
  var startRow = index;  // First row of data to process
  var calId = calId;
  Logger.log(calId);
  Logger.log(startRow);
  Logger.log(added);
  Logger.log(modified);
  if (modified - added > "0"){
    var numRows = 1;   // Number of rows to process
    var dataRange = sheet.getRange(startRow, 1, numRows, 9);
    var data = dataRange.getValues();
    var cal = CalendarApp.getCalendarById(calId);
    for (i in data) {
      var row = data[i];
      var eventId = row[0]
      var title = row[1];  // First column
      var desc = row[2];       // Second column
      var tstart = row[3];
      var tstop = row[4];
      var loc = row[5];
      var guests = row[6];
      //cal.createEvent(title, new Date("March 3, 2010 08:00:00"), new Date("March 3, 2010 09:00:00"), {description:desc,location:loc});
      var newEvent = cal.createEvent(title, tstart, tstop, {description:desc,location:loc, guests:guests});//.addGuest(guests);
      var newEventId = newEvent.getId();
      Logger.log(newEventId);

    }
  }
}
+1

Gooogle, , script, .

:         :         : ekoleda+devrel@google.com         : -Priority-Medium

โ„– 11 574 ekoleda+devrel@google.com: , addGuest http://code.google.com/p/google-apps-script-issues/issues/detail?id=574

:

https://developers.google.com/apps-script/advanced/calendar

You can use Calendar.Events.patch () to add participants, and if you set the optional sendNotifications parameter to true, the participants will be prompted.

https://developers.google.com/google-apps/calendar/v3/reference/events/patch

Today I will try to solve this problem and then edit this answer to reflect it.

0
source

Source: https://habr.com/ru/post/1530151/


All Articles