我尝试使用RetrieveMultiple方法和查询表达式获取系统用户的所有约会。示例:
WhoAmIRequest userRequest = new WhoAmIRequest();
WhoAmIResponse userResponse = (WhoAmIResponse)_serviceProxy.Execute(userRequest);
QueryExpression qe = new QueryExpression();
qe.EntityName = "systemuser";
...
slos.RetrieveMultiple(qe);
我可以从系统用户实体检索系统用户(所有者,组织者,所需参与者,可选参加者)的所有约会吗?
或者我是否必须检索CRM的所有约会并添加条件以了解用户是所有者,组织者,必需或可选的与会者?
最后,我使用SOAP Logger,它是生成SOAP请求的最佳方式吗?
答案 0 :(得分:2)
您需要在activitypointer
和appointment
之间使用关系实体systemuser
。正如您在我的示例中看到的那样,这会使事情变得有点复杂。
至少有两种方法可以构建您想要的查询:
1)如您所知,您可以按systemuserid过滤约会:
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)您可以通过systemuserid查询systemuser并将约会添加为链接实体(如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 }),
答案 1 :(得分: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);