Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Manually-created AccessTeam is not working in CRM 8.2.2 OnPremise any more

Posted on by 105

Hi CRM Community,

In Dynamics CRM version 8.1 we have the following code working without any problem: it creates an AccessTeam

 - entity - comes as a parameter - type Entity

                var bu = "the root Business Unit";
                var team = new Team
                {
                    Name = "My Custom Access Team Name",
                    TeamType = new OptionSetValue((int)TeamTeamType.Access),
                    AdministratorId = new EntityReference(SystemUser.EntityLogicalName, _Context.UserId),
                    BusinessUnitId = new EntityReference(BusinessUnit.EntityLogicalName, bu.Id),
                };
                team.RegardingObjectId = entity.ToEntityReference();
                team.Id = _Service.Create(team);

As with the version 8.2.2 we cannot use the RegardingObjectId any more - we get the following error message:

[6ad6d959-295c-e711-80e6-005056892d2b: 40_opportunity_create]
Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Only system managed teams can associated with team templates or other records. They can only be created by the system. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).,

We need the AccessTeam created with a specific Name format and the regardingObjectId defined!

If we let the system create the AccessTeam, we cannot change it's name :(

Could anyone give us a helping hand and explain why this happens?

Thank you in advance for your help!

*This post is locked for comments

  • Verified answer
    ratiusv Profile Picture
    ratiusv 105 on at
    RE: Manually-created AccessTeam is not working in CRM 8.2.2 OnPremise any more

    What I have noticed is that the following line is not to be used while creating an AccessTeam manually:

    team.RegardingObjectId = entity.ToEntityReference();

    As it worked with version 8.1, and we have created logic based on this RegardingObjectId field, we have to recode the parts where we use this Attribute.

    Instead of getting the team by entity as RegardingObjectId

    var team = xrm.TeamSet.Where(x => x.RegardingObjectId == entity.ToEntityReference())

    we get the team now as follows:

    private Team GetAccessTeam_ByEntityAndTeamType(Entity entity, SecuritySettings.TeamType teamType)

           {

               // get the access rights the team we are looking for must posess

               AccessRights teamAccessRights = SecuritySettings.GetResolver().GetAccessRights(entity, teamType);

               using (var xrm = new XrmServiceContext(_Service))

               {

                   // search only the specified team

                   foreach (var principalAccess in GetPrincipalAccess(entity.ToEntityReference()))

                   {

                       // if the principalAccess is not a team entRef, then continue

                       if (!principalAccess.Principal.LogicalName.Equals(Team.EntityLogicalName))

                           continue;

                       // if the access rights do not correspond with the one we are searching for, then continue

                       if ((teamAccessRights & principalAccess.AccessMask) != teamAccessRights)

                           continue;

                       // the principalAccess is the team we are looking for.

                       // now get the team entity from the entRef - principalAccess.Principal

                       var team = xrm.TeamSet.Where(x => x.Id.Equals(principalAccess.Principal.Id)).FirstOrDefault();

                       return team;

                   }

               }

               return null;

           }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans