简体   繁体   English

如何在 Dynamics 365 C# 插件中查询用户的团队?

[英]How do I query a user's teams in Dynamics 365 C# plugin?

The example shown here passes in the userID and a string array of security names.此处显示的示例传入userID和安全名称字符串数组。 Then return true if the user has any security roles that match the names.如果用户具有与名称匹配的任何安全角色,则返回 true。

public static bool UserHasRoles(IOrganizationService service, Guid userId, params string[] roleNames)
{
        var query = new QueryExpression("systemuserroles");
        query.TopCount = 1; 
        query.ColumnSet.AddColumns("systemuserroleid");           
        query.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, userId);
        
        var query_role = query.AddLink("role", "roleid", "roleid");            
        query_role.LinkCriteria.AddCondition("name", ConditionOperator.In, roleNames);
        
        var result = service.RetrieveMultiple(query);
        return result.Entities.Any();
}

I need to recreate this code but to return true if the user is part of any teams that contain the same names.我需要重新创建此代码,但如果用户是包含相同名称的任何团队的一部分,则返回 true。 Below is my attempt:以下是我的尝试:

public static bool UserHasRoles(IOrganizationService service, Guid userId, params string[] roleNames)
{
        var query = new QueryExpression("teammembership");
        query.TopCount = 1; 
        query.ColumnSet.AddColumns("teamMembershipId");           
        query.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, userId);

        var query_role = query.AddLink("team", "teamid", "teamid");
        query_role.LinkCriteria.AddCondition("name", ConditionOperator.In, roleNames);
        
        var result = service.RetrieveMultiple(query);

        return result.Entities.Any();
}

When ran the code, I get an error运行代码时,出现错误

'TeamMembership' entity doesn't contain attribute with Name = 'teamMembershipId' and NameMapping = 'Logical' 'TeamMembership' 实体不包含 Name = 'teamMembershipId' 和 NameMapping = 'Logical' 的属性

I'm unsure if I am querying the equivalent entity correctly.我不确定我是否正确查询了等效实体。 Or I may be going about this in completely the wrong way.或者我可能会以完全错误的方式解决这个问题。 Help would be great.帮助会很棒。

Actually, you don't need any column to be returned.实际上,您不需要返回任何列。
Here's your code without ColumnSet line, also I've corrected your method name and parameter name:这是没有ColumnSet行的代码,我还更正了您的方法名称和参数名称:

public static bool UserInTeams(IOrganizationService service, Guid userId, params string[] teamNames)
{
    var query = new QueryExpression("teammembership");
    query.TopCount = 1;
    query.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, userId);
    
    var query_role = query.AddLink("team", "teamid", "teamid");
    query_role.LinkCriteria.AddCondition("name", ConditionOperator.In, teamNames);
    
    var result = service.RetrieveMultiple(query);
    return result.Entities.Any();
}

暂无
暂无

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

相关问题 如何格式化Dynamics 365 C#插件的LINQ查询 - How to format LINQ query for Dynamics 365 c# plugin Dynamics 365(本地):与多个团队共享记录-C# - Dynamics 365 (On-Prem): Share record with multiple teams - C# 如何在带有C#插件的Dynamics CRM组织中使用Dynamics 365 Web API检索所有记录(超过5000页和/或一页以上)? - How can I retrieve all records (more than 5000 and/or more than 1 page) with the Dynamics 365 Web API in a Dynamics CRM organization with a C# plugin? 我在使用C#向Dynamics 365普通用户进行身份验证时遇到错误 - I am getting error on authenticate to dynamics 365 normal user with c# 如何在使用 AAD 进行身份验证的 ASP.NET MVC 站点中以登录用户身份查询 Dynamics 365 CRM? - How can I query Dynamics 365 CRM as the logged in user in an ASP.NET MVC site authenticated with AAD? Dynamics CRM 2013 C#插件的用户设置中的更新/更改系统用户时区 - dynamics crm 2013 c# plugin update/change system user timezone in it's usersettings 如何在 MS Graph C# 中获取所有团队? - How do I get all Teams in MS Graph C#? 如何构建查询以获取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 c# 插件中使用 google lib-phonenumbers - How to use google lib-phonenumbers in dynamics c# plugin 如何在特定字段值上触发动态 c# 插件 - How to fire a dynamics c# plugin on specific field value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM