Skip to content

Commit d79179e

Browse files
authored
Merge pull request #1185 from SherpasGroup/fix-group-id
Fix for getting the unified group id efter creating a new group
2 parents 33c8fb0 + de0e528 commit d79179e

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/lib/PnP.Framework/Graph/UnifiedGroupsUtility.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -252,24 +252,31 @@ public static UnifiedGroupEntity CreateUnifiedGroup(string displayName, string d
252252

253253
int driveRetryCount = retryCount;
254254

255-
while (driveRetryCount > 0 && string.IsNullOrEmpty(modernSiteUrl))
255+
if (addedGroup.AdditionalData?.TryGetValue("id", out var groupId) == true)
256256
{
257-
try
258-
{
259-
modernSiteUrl = GetUnifiedGroupSiteUrl(addedGroup.GroupId, accessToken, azureEnvironment: azureEnvironment);
260-
}
261-
catch
257+
while (driveRetryCount > 0 && string.IsNullOrEmpty(modernSiteUrl))
262258
{
263-
// Skip any exception and simply retry
264-
}
259+
try
260+
{
261+
modernSiteUrl = GetUnifiedGroupSiteUrl(groupId.ToString(), accessToken, azureEnvironment: azureEnvironment);
262+
}
263+
catch
264+
{
265+
// Skip any exception and simply retry
266+
}
265267

266-
// In case of failure retry up to 10 times, with 500ms delay in between
267-
if (string.IsNullOrEmpty(modernSiteUrl))
268-
{
269-
Task.Delay(delay * (retryCount - driveRetryCount)).GetAwaiter().GetResult();
270-
driveRetryCount--;
268+
// In case of failure retry up to 10 times, with 500ms delay in between
269+
if (string.IsNullOrEmpty(modernSiteUrl))
270+
{
271+
Task.Delay(delay * (retryCount - driveRetryCount)).GetAwaiter().GetResult();
272+
driveRetryCount--;
273+
}
271274
}
272275
}
276+
else
277+
{
278+
throw new Exception("Could not find the group id in the additional data returned from the Graph when creating the unified group");
279+
}
273280

274281
group.SiteUrl = modernSiteUrl;
275282
}

0 commit comments

Comments
 (0)