简体   繁体   中英

"An error occurred while looking up roles in the group" after creating groups in App Script

I have a very simple function that checks if a google (workspace) group exists and if not creates it.

This part works perfectly (group is created and I see it in the google admin dashbard) but if the same function is run again (on the now created group) it fails with the very unspecific error: An error occurred while looking up roles in the group: mygroupname@mydomain.at

My best guess was that because the group was created empty it had some problems when accessing the roles but I joined a test group and am still getting the same error.

Here's my simple function:

function createGroupIfNotExists(email)
{
  try
  {
    var group = GroupsApp.getGroupByEmail(email);
    console.log(" [i+] Group "+email+" Found!");
  }
  catch(e)
  {
    console.log(e)
    console.log(" [i-] Group "+email+" Not found.. creating");
    var emailObj = {
           "email":  email,
            "name": "Group "+email,
           "description": "the new group of "+email
          }
    var newGroup = AdminDirectory.Groups.insert( emailObj );
  }
}

GroupsApp documentation specifies: A group object whose members and those members' roles within the group can be queried.

If you create a group without member roles, you cannot retrieve it with the GroupsApp - use AdminDirectory.Groups.get(email) instead:

function createGroupIfNotExists(email)
{
  try
  {
    var group = AdminDirectory.Groups.get(email)// GroupsApp.getGroupByEmail(email);
    console.log(" [i+] Group "+email+" Found!");
  }
  catch(e)
  {
    console.log(e)
    console.log(" [i-] Group "+email+" Not found.. creating");
    var emailObj = {
           "email":  email,
            "name": "Group "+email,
           "description": "the new group of "+email
          }
    var newGroup = AdminDirectory.Groups.insert( emailObj );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM