Reputation: 21
Isn't there a possibility to get the name of a Google group?
At the moment, I use this code:
function myFunction() {
var groups=["[email protected]","[email protected]"];
var sheet = SpreadsheetApp.getActiveSheet();
for (var a=0;a<groups.length;a++){
var group = GroupsApp.getGroupByEmail(groups[a]);
var users = group.getUsers();
sheet.getRange(1,a+1).setValue(groups[a]);
sheet.getRange(1,a+1).setFontSize(12)
for (var i = 0; i < users.length; i++) {
var user = users[i];
sheet.getRange(i+2,a+1).setValue(user.getEmail());
}
}
}
This code is working perfectly and writes the email of the group in the header row. But I need something like "group.getName()" to write the NAME of the group in the header row.
Franz
Upvotes: 2
Views: 444
Reputation: 1574
The GroupsApp
will not give you this. AdminGroupsSettings
is what your are looking for. You will be able to get more information like description as well. Your new code will look like this.
function myFunction() {
var groups=["[email protected]","[email protected]"];
var sheet = SpreadsheetApp.getActiveSheet();
for (var a=0;a<groups.length;a++){
var group = GroupsApp.getGroupByEmail(groups[a]);
var users = group.getUsers();
sheet.getRange(1,a+1).setValue(AdminGroupsSettings.Groups.get(groups[a]).name);
sheet.getRange(1,a+1).setFontSize(12)
for (var i = 0; i < users.length; i++) {
var user = users[i];
sheet.getRange(i+2,a+1).setValue(user.getEmail());
}
}
}
Ofcourse, for this to work:
Groups Settings API
in Advanced Google Services
under Resources
.Google Developers Console
link in the popup and enable Groups Settings API
in the console there.I checked, this works.
Upvotes: 1