Created
November 30, 2015 12:29
-
-
Save dkudelko/f9773f3e401381abfcbb to your computer and use it in GitHub Desktop.
CRM Plugin sample code get/check user in specific role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static bool UserInFrozenRole(IPluginExecutionContext context, IOrganizationService organizationService, IEnumerable<string> settingRoles) | |
{ | |
var jjQuery = new QueryExpression() | |
{ | |
EntityName = "role", | |
ColumnSet = new ColumnSet("name"), | |
LinkEntities = | |
{ | |
new LinkEntity | |
{ | |
LinkFromEntityName = Role.EntityLogicalName, | |
LinkFromAttributeName = "roleid", | |
LinkToEntityName = SystemUserRoles.EntityLogicalName, | |
LinkToAttributeName = "roleid", | |
LinkCriteria = new FilterExpression | |
{ | |
FilterOperator = LogicalOperator.And, | |
Conditions = | |
{ | |
new ConditionExpression | |
{ | |
AttributeName = "systemuserid", | |
Operator = ConditionOperator.Equal, | |
Values = {context.InitiatingUserId} | |
} | |
} | |
} | |
} | |
} | |
}; | |
var userRoles = organizationService.RetrieveMultiple(jjQuery); | |
return userRoles.Entities.ToList().ToList().Find(r => settingRoles.Contains((string)r.Attributes["name"])) != null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment