简体   繁体   English

如何通过SDK在MS Dynamics CRM中检测用户是否具有管理员角色?

[英]How to detect a user is has administrator role in MS Dynamics CRM via SDK?

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. MS建议的方法是查询角色名称 “administrator”等。

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, ie what was "administrator" could now be an "администратор". 问题在于,由于某种原因,角色名称似乎被翻译 ,因此使用不同语言查询它有点困难,即“管理员”现在可能是“администратор”。

*Using the role id does not seem to work either, on different version of CRM at least. *使用角色ID似乎也不起作用,至少在不同版本的CRM上。

Have anybody ever struggled with such a thing? 有没有人在这样的事情上挣扎过? Gladly appreciate your help! 非常感谢你的帮助!

The system administrator role can be identified using the ID of a role template. 可以使用角色模板的ID来标识系统管理员角色。 For built-in security roles Dynamics CRM systems all share the same Guid s, so you can simply hard code your language-agnostic query. 对于内置安全角色,Dynamics CRM系统都共享相同的Guid ,因此您可以简单地对与语言无关的查询进行硬编码。

Here a code sample. 这是一个代码示例。 (In this example _service should be an object implementing the IOrganizationService interface.) (在此示例中,_service应该是实现IOrganizationService接口的对象。)

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在服务器端的MS Dynamics CRM中获得当前的用户特权 - How to get current user privileges in MS Dynamics CRM on server side 如何以编程方式让用户在MS CRM业务部门中获得特定角色 - How to programmatically get user with specific role in MS CRM business unit 如何在MS Dynamics CRM中通过QuoteDetail获取Opportunity产品? - How to get Opportunityproduct by QuoteDetail in MS Dynamics CRM? 使用XRM SDK从ms dynamics crm获取相关数据 - get related data from ms dynamics crm using XRM SDK 如何构建查询以获取Dynamics CRM 2016 C#中不存在用户X的安全角色 - How to build a query to get a security role where user X does not exists in Dynamics CRM 2016 C# 更改用户角色分配时触发Dynamics CRM 2016插件 - Dynamics CRM 2016 Plugin triggered when user role assignments are changed Dynamics CRM 4 SDK中的换行符 - dynamics crm 4 newlines in sdk 通过Dynamics CRM SDK导入帐户和联系人Zip文件 - Import Accounts and Contacts Zip File via the Dynamics CRM SDK 获取当前登录到MS Dynamics CRM 2011 Online的用户的ID - Get Id of user currently logged into MS Dynamics CRM 2011 Online 发生错误。 请与系统管理员联系,或参阅Microsoft Dynamics CRM SDK故障排除指南 - An error occurred. Contact a system administrator or refer to the Microsoft Dynamics CRM SDK troubleshooting guide
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM