Reputation: 612
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: [email protected]
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 );
}
}
Upvotes: 0
Views: 864
Reputation: 26796
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 );
}
}
Upvotes: 1