[英]Dynamics CRM : Retrieve multiple appointments for a systemuser
我正在嘗試使用RetrieveMultiple方法和查詢表達式來獲取系統用戶的所有約會。 范例:
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請求的最佳方法嗎?
您將需要使用appointment
和systemuser
之間的關系實體activitypointer
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),
},
},
};
關於參與角色的過濾器,您必須在activitypointer
的participationtypemask
上添加一個條件:
// user is Organizer, Owner, required or optional Attendee
ConditionExpression("participationtypemask", ConditionOperator.In, new int[] { 5, 6, 7, 9 }),
有了這個表達,我現在沒有收到任何約會:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.