0
  • I'm trying to invite members of a group to calendar events in batch
  • If I invite the group using its email the group is splitted in the event (which is normal) but the invitations are not 'validated'... I can validate them manually in the calendar interface but that's not a solution. In the end the guest are not invited even if their names appear in the event. If I don't 'save' this event manually the log shows the group as only guest, not its users.

So I tried to add every guest separately using the script below but I get an error that I don't understand enter image description here The error comes after a variable number of successful invitation on the first event... sometimes just one, sometimes 2 or 3 or 5... randomly.

This is running on a google apps education account on a domain. I have admin privileges and I have all rights on the calendars.

Here is the code of the relevant function : ( get the group members, invite them for every events in the period of time, print out a resulting log on a new sheet.)

function sendinvites(e) {
  var calendar_name = e.parameter.calendar;
  var email = calendar_name.toLowerCase()+'@insas.be';
  var group = GroupsManager.getGroup(email);
  var members = group.getAllMembers();
  var startDate = new Date(e.parameter.start);
  var endDate = new Date(e.parameter.end);
  var Calendar = CalendarApp.getCalendarsByName(calendar_name);
  var sheetName = calendar_name + "-du-" + Utilities.formatDate(e.parameter.start, FUS1, "dd-MMM-yyyy")
      + "-au-" + Utilities.formatDate(e.parameter.end, FUS1, "dd-MMM-yyyy")  
// 
  var events = Calendar[0].getEvents(startDate , endDate);
  if (events[0]) {
    var eventarray = new Array();
    var line = new Array();
    line.push('Titre : '+calendar_name,'Début ','Fin','Localisation','Durée','invités');
    eventarray.push(line);

    for (i = 0; i < events.length; i++) {
      if(events[i].getTitle().match('semaine n')=='semaine n'){continue}
    var lr = logsheet.getLastRow(); // these lines are added here for test purpose only, to see where in the loop it fails... that's why I set values cell by cell !
      logsheet.getRange(lr+1,1).setValue(events[i].getTitle()+' / '+Utilities.formatDate(events[i].getStartTime(), FUS1, "dd-MMM-yyyy"));
      for(nn=0;nn<members.length;++nn){
        logsheet.getRange(lr+1,nn+2).setValue(members[nn]);  
        events[i].addGuest(members[nn])
            }
      line = new Array();
      line.push(events[i].getTitle());
      line.push(Utilities.formatDate(events[i].getStartTime(), FUS1, "dd-MMM-yyyy")+' à ' +Utilities.formatDate(events[i].getStartTime(), FUS1, "HH:mm"));
      line.push(Utilities.formatDate(events[i].getEndTime(), FUS1, "dd-MMM-yyyy")+' à ' +Utilities.formatDate(events[i].getEndTime(), FUS1, "HH:mm"));
      line.push(events[i].getLocation());
      line.push((events[i].getEndTime() - events[i].getStartTime()) / 3600000);
      var invitelist='';
      var list = events[i].getGuestList()
          for(nn=0;nn<list.length;++nn){invitelist+=list[nn].getName()+', '}
      line.push(invitelist)
      eventarray.push(line);
    }
    Logger.log(eventarray)
    var sheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet(sheetName);
    sheet.getRange(1,1,eventarray.length,eventarray[0].length).setValues(eventarray);
    sheet.getRange(1,1,1,eventarray[0].length).setBackgroundColor('#ffffcc');
    sheet.setColumnWidth(1, 450);sheet.setColumnWidth(2, 150);sheet.setColumnWidth(3, 150);sheet.setColumnWidth(4, 250);sheet.setColumnWidth(5, 75);sheet.setColumnWidth(6, 450);;
    sheet.setFrozenRows(1)
  } else {
    var startstring = Utilities.formatDate(e.parameter.start, FUS1, "dd-MMM-yyyy");
    var endstring = Utilities.formatDate(e.parameter.end, FUS1, "dd-MMM-yyyy");
    Browser.msgBox('Aucun événement entre le ' + startstring + ' et le ' + endstring +' dans votre agenda :'+calendar_name);
  }

  var app = UiApp.getActiveApplication();
  app.close();
  return app;  
}

So my question is : is it the right approach ? should I invite the group by its email and in this case how can I get this group splitted in each one calendar automatically ?

Has anybody ever meet this situation ?

I'm kind of stuck here :-/

ref : issue tracker 1906 merged with 264 see own answer for details

4

2 に答える 2

0

http://code.google.com/p/google-apps-script-issues/issues/detail?id=264#c40によると

This exception error is not a bug. 
This issue occurs only when one event is being modified by multiple parties simultaneously. 
It is thrown intentionally to prevent a loss of data.

スクリプトのパーツ間でスリープ コードを使用してみてください。

Utilities.sleep(2000);
于 2012-10-06T12:45:15.190 に答える
0

イシュー トラッカーを読むと、毎回個別にイベントを取得し、一度に 1 人のゲストを追加するという、この問題に対する有効な回避策があるようです。

これは恐ろしく遅いですが、明らかにエラーなしで実行されます (今のところ ;-)

非常に不快なので、Googleがこの動作を変更することを願っています!!

コードは非常に遅いため、15 人のゲストが参加する 20 のイベントの後でタイムアウトします... 非常に幸いなことに、追加したログ シートにはコードが停止した場所が示され、日付を設定するために使用する UI はタイムアウト後も開いたままになっています。9 月から 6 月まで 20 枚のカレンダーがいっぱいになるのを待って、これから数日間はコーヒーをたくさん飲むことになると思います。;-P


ここに変更されたコードがあります(変更された部分)

for (i = 0; i < events.length; i++) {
  if(events[i].getTitle().match('semaine n')=='semaine n'){continue}
    var ID = events[i].getId(); // get the ID to be able to recall the event later
var lr = logsheet.getLastRow();
  logsheet.getRange(lr+1,1).setValue(events[i].getTitle()+' / '+Utilities.formatDate(events[i].getStartTime(), FUS1, "dd-MMM-yyyy"));
  for(nn=0;nn<members.length;++nn){
    logsheet.getRange(lr+1,nn+2).setValue(members[nn]);  
    Calendar[0].getEventSeriesById(ID).addGuest(members[nn]);// separately get each event and add guest
  }
  line = new Array();
  line.push(events[i].getTitle());
  line.push(Utilities.formatDate(events[i].getStartTime(), FUS1, "dd-MMM-yyyy")+' à ' +Utilities.formatDate(events[i].getStartTime(), FUS1, "HH:mm"));
  line.push(Utilities.formatDate(events[i].getEndTime(), FUS1, "dd-MMM-yyyy")+' à ' +Utilities.formatDate(events[i].getEndTime(), FUS1, "HH:mm"));
  line.push(events[i].getLocation());
  line.push((events[i].getEndTime() - events[i].getStartTime()) / 3600000);
  var invitelist='';
  var list = Calendar[0].getEventSeriesById(ID).getGuestList()
      for(nn=0;nn<list.length;++nn){invitelist+=list[nn].getName()+', '}
  line.push(invitelist)
  eventarray.push(line);
}
于 2012-10-06T19:09:20.470 に答える