To add members in google group from spreadsheet

266 views
Skip to first unread message

Khushi P

unread,
May 27, 2022, 7:27:41 AM5/27/22
to Google Apps Script Community
{ [Exception: An error occurred while fetching the member list for the group: projec...@googlegroups.com] name: 'Exception' }

does anyone know why I'm getting this error?
I'm a beginner in apps Script

Khushi P

unread,
May 27, 2022, 7:29:36 AM5/27/22
to Google Apps Script Community
function addMembersFromSheet() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var emails = sheet.getRange(2,2,sheet.getLastRow()-1,1).getValues();
  var group = GroupsApp.getGroupByEmail("projec...@googlegroups.com");
for(i = 0; i < emails.length; i++) {
    try {
      addMember(emails[i][0], group);
    }
    catch(e) {
      console.error(e);
      continue;
    }   
  }
}
function addMember(email, group) {
  
  var hasMember = group.hasUser(email);
  Utilities.sleep(1000);
  
  if(!hasMember) {
    var newMember = {email: email, 
                     role: "MEMBER",
                     delivery_settings: "NONE"};
    AdminDirectory.Members.insert(newMember, GROUP_ID);
  }
}

This is the code. I dont  have a G-suit account , is it possible to add members inn Google group without that?

Clark Lind

unread,
May 27, 2022, 9:15:31 PM5/27/22
to Google Apps Script Community
No, it shouldn't be possible. Otherwise, you could add someone to every group against their will. In a domain/G-suite/Workspace account, Admins have the ability to add domain members to domain groups, but I don't believe it is possible out here in the wild :)
Reply all
Reply to author
Forward
0 new messages