Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Create a team and assign security role on it while create BusinessUnit (Click on Save BU) - plugin

Posted on by Microsoft Employee

Hello Everyone,

I have created the Post-Operation create plugin and 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)});

*This post is locked for comments

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