- 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 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