2015-10-22 96 views
0

我试图通过RetrieveMultiple方法和查询表达式获取systemuser的所有约会。例如:Dynamics CRM:为系统用户检索多个约会

WhoAmIRequest userRequest = new WhoAmIRequest(); 
WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest); 

QueryExpression qe = new QueryExpression(); 
qe.EntityName = "systemuser"; 

... 
slos.RetrieveMultiple(qe); 

我可以从systemuser实体检索systemuser(所有者,组织者,参加者需要,可选的与会者)的所有的约会?

或者是否必须检索CRM的所有约会并添加条件以了解用户是所有者,组织者,必需的还是可选的与会者?

最后,我使用SOAP Logger,它是生成SOAP请求的最佳方式吗?

回答

2

您需要使用appointmentsystemuser之间的关系实体activitypointer。正如你在我的例子中看到的那样,这会让事情变得复杂一些。

至少有2种可能的方式来建立你所需的查询:

var qe = new QueryExpression 
{ 
    EntityName = "appointment", 
    ColumnSet = new ColumnSet("subject"), 
    LinkEntities = 
    { 
     new LinkEntity 
     { 
      EntityAlias = "ap", 
      JoinOperator = JoinOperator.Inner, 
      Columns = new ColumnSet(false), 
      LinkFromEntityName = "appointment", 
      LinkFromAttributeName = "activityid", 
      LinkToEntityName = "activityparty", 
      LinkToAttributeName = "activityid", 
      LinkCriteria = new FilterExpression 
      { 
       Conditions = 
       { 
        new ConditionExpression("partyid", ConditionOperator.Equal, userid), 
       }, 
      }, 
     }, 
    }, 
}; 

2)您可以通过查询systemuser:

1)正如你已经想通,您可以通过systemuserid筛选约会systemuserid并添加任命为链接的实体(如在一个SQL查询JOIN):

var qe2 = new QueryExpression 
{ 
    EntityName = "systemuser", 
    ColumnSet = new ColumnSet(false), 
    LinkEntities = 
    { 
     new LinkEntity 
     { 
      EntityAlias = "ap", 
      Columns = new ColumnSet(false), 
      JoinOperator = JoinOperator.Inner, 
      LinkFromEntityName = "systemuser", 
      LinkFromAttributeName = "systemuserid", 
      LinkToEntityName = "activityparty", 
      LinkToAttributeName = "partyid", 
      LinkEntities = 
      { 
       new LinkEntity 
       { 
        EntityAlias = "a", 
        Columns = new ColumnSet("subject"), 
        JoinOperator = JoinOperator.Inner, 
        LinkFromEntityName = "activityparty", 
        LinkFromAttributeName = "activityid", 
        LinkToEntityName = "appointment", 
        LinkToAttributeName = "activityid", 
       }, 
      }, 
     }, 
    }, 
    Criteria = new FilterExpression 
    { 
     Conditions = 
     { 
      new ConditionExpression("systemuserid", ConditionOperator.Equal, userid), 
     }, 
    }, 
}; 

,关于对参与角色的过滤器,你就必须在participationtypemask添加一个条件在activitypointer

// user is Organizer, Owner, required or optional Attendee 
ConditionExpression("participationtypemask", ConditionOperator.In, new int[] { 5, 6, 7, 9 }), 
+0

非常感谢您的回答,这样可以节省我的一天。还有一件事,如果在ColumnSet中设置了“组织者”,它将检索包含所有字段的EntityCollection。是否可以在组织者中指定我想要的字段? – bidou88

+1

当然这是可能的 - 而不是像我的expample中那样只指定*“subject”*,你可以简单地设置'new ColumnSet(true)'来检索所有的字段。如果您需要根据条件构建QueryExpression,请将其分开并根据需要设置属性。我倾向于以所示的方式构造QueryExpression,因为它使它们更像SQL查询的可读性。 – Filburt

+0

谢谢,我没有说好我的问题。如果在我的ColumnSet中添加组织者,它将检索组织者,但所有字段都附加到组织者。我想要做的只是在组织者中只有特定的领域。我不知道是否清楚? – bidou88

0

有了这个表达,我没有收到任何的任命现在:

QueryExpression qe = new QueryExpression 
{ 
    EntityName = "appointment", 
    ColumnSet = new ColumnSet("activityid", "subject", "scheduledstart", "scheduledend", "location", "description"), 
    Criteria = new FilterExpression 
    { 
     FilterOperator = LogicalOperator.And, 
     Conditions = 
     { 
      new ConditionExpression("scheduledend", ConditionOperator.GreaterThan, startTime), 
      new ConditionExpression("scheduledstart", ConditionOperator.LessThan, endTime) 
     } 
    }, 
    LinkEntities = 
    { 
     new LinkEntity 
     { 
      LinkFromEntityName = "activitypointer", 
      LinkFromAttributeName = "activityid", 
      LinkToEntityName = "activityparty", 
      LinkToAttributeName = "activityid", 
      LinkCriteria = new FilterExpression 
      { 
       FilterOperator = LogicalOperator.And, 
       Conditions = 
       { 
        new ConditionExpression("participationtypemask", ConditionOperator.In, new int[] { 5, 6, 7, 9 }), 
        new ConditionExpression("partyid", ConditionOperator.Equal, userResponse.UserId) 

       } 
      } 
     }, 
     new LinkEntity 
     { 
      EntityAlias = "requiredattendees", 
      Columns = new ColumnSet(false), 
      JoinOperator = JoinOperator.Inner, 
      LinkFromEntityName = "activitypointer", 
      LinkFromAttributeName = "activityid", 
      LinkToEntityName = "activityparty", 
      LinkToAttributeName = "activityid", 
      LinkCriteria = new FilterExpression 
      { 
       Conditions = 
       { 
        new ConditionExpression("participationtypemask", ConditionOperator.Equal, 5) 

       } 
      }, 
      LinkEntities = 
      { 
       new LinkEntity 
       { 
        EntityAlias = "contact", 
        Columns = new ColumnSet("fullname"), 
        JoinOperator = JoinOperator.Inner, 
        LinkFromEntityName = "activityparty", 
        LinkFromAttributeName = "activityid", 
        LinkToEntityName = "contact", 
        LinkToAttributeName = "contactid" 
       }, 
      } 
     } 
    } 
}; 

qe.Distinct = true; 

slos.RetrieveMultiple(qe); 
+0

乍一看我会说你的问题是现在你指定'JoinOperator.Inner'在你的* requiredattendees *和* contact * LinkEntities(应该是JoinOperator.LeftOuter)。如果我发现自己有这样的意外结果,我尝试使用“高级查找”来重建查询并检查它后面的FetchXml。这通常会很快清理事情。附注:您可能希望将此“答案”的内容作为新问题移至原始帖子或帖子。 – Filburt

相关问题