2017-07-17 11 views
1

私は、すべてのアポイントエンティティとその必要な出席者(私の場合は常に連絡先タイプ)のすべての情報をプログラムで取得したいと考えました。Dynamics CRMのアポイントエンティティの必要な出席者と連絡先に参加

アポイントエンティティ「必須出席者」属性に基づいてアポイントエンティティと連絡先エンティティを結合する最良の方法は何ですか? 「必要な参加者」を取得するには

答えて

4

、あなたはAppointmentActivityPartyエンティティ間の結合を行い、その後、「必要な出席者のために5であるParticipationTypeMaskに基づいてフィルタリングする必要があります。 さらに、ActivityPartyContactエンティティの間で結合を行う必要があります。

あなたのコードは次のように考えられます。

//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(); 
} 
関連する問題