在 Dynamics CRM 中加入约会实体所需的参加者和联系人实体
Joining Appointment Entity's Required Attendees and Contact Entity in Dynamics CRM
我想以编程方式提取所有约会实体及其所需与会者的完整信息(在我的情况下始终是联系人类型)。
根据约会实体 "Required Attendees" 属性连接约会实体和联系人实体的最佳方式是什么?
要获得 'Required Attendees',您需要在 Appointment
和 ActivityParty
实体之间进行连接,然后根据 ParticipationTypeMask 进行过滤,对于 'Required Attendees'。
此外,您需要在 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();
}
我想以编程方式提取所有约会实体及其所需与会者的完整信息(在我的情况下始终是联系人类型)。
根据约会实体 "Required Attendees" 属性连接约会实体和联系人实体的最佳方式是什么?
要获得 'Required Attendees',您需要在 Appointment
和 ActivityParty
实体之间进行连接,然后根据 ParticipationTypeMask 进行过滤,对于 'Required Attendees'。
此外,您需要在 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();
}