[英]Joining Appointment Entity's Required Attendees and Contact Entity in Dynamics CRM
我想以編程方式提取所有約會實體及其所需參與者的完整信息(在我的情況下,總是聯系類型)。
基於約會實體“必需出席者”屬性的約會實體和聯系人實體之間最佳的聯接方式是什么?
要獲取“必需的與會者”,您需要在Appointment
和ActivityParty
實體之間建立Appointment
,然后根據ParticipationTypeMask進行過濾,其中“必需的與會者”為5。 此外,您需要在ActivityParty
和Contact
實體之間建立ActivityParty
。
您的代碼可能與此類似:
//Create a query expression specifying the link entity alias
//and the columns of the link entity that you want to return
QueryExpression qe = new QueryExpression();
qe.EntityName = "appointment";
qe.ColumnSet = new ColumnSet(true);
//LinkEntity for ActivityParty
var activityParty = new LinkEntity()
{
EntityAlias = "activityparty",
JoinOperator = JoinOperator.Inner,
Columns = new ColumnSet(true),
LinkFromEntityName = "appointment",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "activityid",
LinkCriteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("participationtypemask", ConditionOperator.Equal, 5), //Required Attendees
new ConditionExpression("partyobjecttypecode", ConditionOperator.Equal, 2), // Contacts
}
}
};
//LinkEntity for Contact
var contact = new LinkEntity()
{
EntityAlias = "contact",
JoinOperator = JoinOperator.Inner,
Columns = new ColumnSet(true),
LinkFromEntityName = "activityparty",
LinkFromAttributeName = "partyid",
LinkToEntityName = "contact",
LinkToAttributeName = "contactid",
};
activityParty.LinkEntities.Add(contact);
qe.LinkEntities.Add(activityParty);
//Get the appointments and the Linked Entities
var appointments = _orgService.RetrieveMultiple(qe);
foreach (var appointment in appointments.Entities)
{
// Do something with the Contact Data
var fullname = ((AliasedValue)(appointment["contact.fullname"])).Value.ToString();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.