In this method we use query expression to retrieve the system user specifying a link to entity "SystemUserRoles" and then a link to the "Role" entity. The linking attribute is the SystemUserId for the first link and the RoleId for the second one.
Finally a condition on the role's name to filter the system users.
public EntityCollection
RetrieveUsersInfoByRole(string roleName,
string[] userColumnSet)
string[] userColumnSet)
{
try
{
serviceProxy = ServiceConnector.
GetOrganizationService("<Organization.svc URL>");
QueryExpression query = new
QueryExpression("systemuser");
query.ColumnSet = new ColumnSet(userColumnSet);
query.Distinct = true;
query.Criteria = new FilterExpression();
//Add link to system user roles and role
query.AddLink("systemuserroles",
"systemuserid", "systemuserid").
AddLink("role", "roleid", "roleid").LinkCriteria.
AddCondition("name", ConditionOperator.Equal,
roleName);
EntityCollection users =
serviceProxy.RetrieveMultiple(query);
return users;
}
catch (Exception
ex)
{
throw ex;
}
}
Hope it can be useful.
Happy CRM coding
Rate this posting:
{[['']]}
My friend recommended this blog and he was totally right keep up the fantastic work!
ReplyDeleteMathCad Online Project Help