I have a small issue with detecting whether the user in a company is an admin or not. A suggested way to do that by MS is to query for a role name "administrator" etc.
BUT the thing is that it is for some reason the role names seem to be translated, so it makes it a bit difficult to query for it in different languages, i.e. what was "administrator" could now be an "администратор".
*Using the role id does not seem to work either, on different version of CRM at least.
Have anybody ever struggled with such a thing? Gladly appreciate your help!
Navigate to Settings > System > Security. Select the Security roles icon. You now see a list of security roles.
To assign a role in Dynamics 365 Sales Professional: Under Standard Settings, select Manage users. Select a user you want to assign a role to, and then on the command bar, select Manage Roles. In the Manage User Roles dialog box, select the security role or roles you want for the user or users, and then select OK.
The system administrator role can be identified using the ID of a role template. For built-in security roles Dynamics CRM systems all share the same Guid
s, so you can simply hard code your language-agnostic query.
Here a code sample. (In this example _service should be an object implementing the IOrganizationService
interface.)
private static readonly Guid AdminRoleTemplateId = new Guid("627090FF-40A3-4053-8790-584EDC5BE201");
public bool HavingAdminRole(Guid systemUserId)
{
var query = new QueryExpression("role");
query.Criteria.AddCondition("roletemplateid", ConditionOperator.Equal, AdminRoleTemplateId);
var link = query.AddLink("systemuserroles", "roleid", "roleid");
link.LinkCriteria.AddCondition("systemuserid", ConditionOperator.Equal, systemUserId);
return _service.RetrieveMultiple(query).Entities.Count > 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With