1
我想以編程方式提取所有約會實體及其所需的與會者的全部信息(在我的案例中始終爲聯繫人類型)。在Dynamics CRM中加入約會實體所需的與會者和聯繫人實體
基於約會實體「必需參加者」屬性,在約會實體和聯繫人實體之間加入最佳方式是什麼?
我想以編程方式提取所有約會實體及其所需的與會者的全部信息(在我的案例中始終爲聯繫人類型)。在Dynamics CRM中加入約會實體所需的與會者和聯繫人實體
基於約會實體「必需參加者」屬性,在約會實體和聯繫人實體之間加入最佳方式是什麼?
要獲得'所需參加者',您需要在Appointment
和ActivityParty
實體之間進行連接,然後根據ParticipationTypeMask進行過濾,這對於'所需參加者'爲5。 此外,您需要在ActivityParty
和Contact
實體之間進行連接。
你的代碼可能是與此類似:
//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();
}