Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Unable to assign Security Role to a team, it throws an error as "The team belongs to a different business unit than the role."

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I need to create team and assign role to it on Business Unit Create.So

I have created the Post-Operation business Unit create plugin to created team which is working fine. Now, I tried to assign role to team like as

QueryExpression query = new QueryExpression

{

EntityName = Role.EntityLogicalName,

ColumnSet = New ColumnSet("roleid"),

Criteria = new FilterExpression

{

FilterOperator = LogicalOperator.And,

Condition =

{new ConditionExpression{AttributeName="name", Operator = ConditionOperator.Equal, Values = {SecurityRoleName}}},

{new ConditionExpression{AttributeName="businessunitid", Operator = ConditionOperator.Equal, Values = {budinessUnitId}}},

}

};

EntityCollection roles = _service.RetrieveMultiple(query);

if(roles.Entities.Count > 0)

{ Role _role = roles.Entities[0].ToEntity<Role>();

roleId = _role.Id }

But it doesn't fetch the records

 If I query from only by name, it fetches the record. After that, I try to associate the role to the team but it throws an error as

"The team belongs to a different business unit than the role."

_service.Associate( "team", teamId,

new Relationship("teamroles_association"),

new EntityReferenceCollection(){ new EntityReference("role", roleId)});

Please can anyone help me on this issue

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to assign Security Role to a team, it throws an error as "The team belongs to a different business unit than the role."

    Asynchronously plugin worked but I was unaware of needing to attach CRM service while debugging for it. Anyway it has worked and I really appreciate for your information.

    Thank you David

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Unable to assign Security Role to a team, it throws an error as "The team belongs to a different business unit than the role."

    It looks like the security role for the business unit has not been created by the time your code runs. The security roles are created automatically by CRM, but it may be that is an asynchronous process.

    I'd suggest registering your plugin to run asynchronously, though I'm not sure you can be certain it will run after the security role creation, if that is also an asynchronous process.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans