Skip to content

Instantly share code, notes, and snippets.

@tomwassenberg
Last active June 21, 2018 14:31
Show Gist options
  • Save tomwassenberg/6c701c2ed7b92871343f13f40c15ac51 to your computer and use it in GitHub Desktop.
Save tomwassenberg/6c701c2ed7b92871343f13f40c15ac51 to your computer and use it in GitHub Desktop.
Functions to get info about Google Groups from the G Suite API in a Google spreadsheet
function showMyGroups() {
var current_sheet;
var groups;
current_sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
groups = GroupsApp.getGroups();
if (groups.length > 0) {
current_sheet.clearContents();
current_sheet.getRange(1, 1).setValue("You are a member of " + groups.length + " groups:");
current_sheet.setColumnWidth(1, 240)
for (var i = 0; i < groups.length; i++) {
current_sheet.getRange(i+1, 2).setValue(groups[i].getEmail());
}
}
}
function listMembersOfGroup() {
var current_sheet;
var groupEmail;
var members;
current_sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
groupEmail = Browser.inputBox("Mailinglist", "Which group do you want to know the members of?", Browser.Buttons.OK_CANCEL);
try {
members = GroupsApp.getGroupByEmail(groupEmail).getUsers();
current_sheet.clearContents();
current_sheet.getRange(1, 1).setValue("Members of " + groupEmail + ":");
current_sheet.setColumnWidth(1, 240)
for (var i = 0; i < members.length; i++) {
current_sheet.getRange(i+1, 2).setValue(members[i].getEmail());
}
}
catch(exception) {
Browser.msgBox("Error", exception, Browser.Buttons.OK);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment