2017-10-29 3 views
0

私はアカウントIDを持っており、メールリストを作成するためにアカウントの連絡先のコレクションを取得したいと考えています。アカウントの連絡先をすべて取得し、電子メールリストをMS Dynamics CRMに作成する方法は?


//build up Email 
    private Email BuildEmail(ActivityParty allcontacts){.... build my emailhere} 

    private List<Entity> GetAllContactsFromAccountId(Guid accountId, List<Entity> toList) 
    {   

     //how can I get all the contacts here 
     foreach (Entity contact in Account.Contact.Entities)//???? 
     { 
      Entity activityParty = new Entity("activityparty"); 
      activityParty["partyid"] = new EntityReference("??", e.Id); 

      if (toList.Any(t => t.GetAttributeValue<EntityReference>("partyid").Id == e.Id)) continue; 

      toList.Add(activityParty); 
     } 

     return toList; 
    } 

答えて

0

あなたは、コンタクトエンティティにアカウントキー "parentcustomerid" を見つけることができます。以下のようにアカウントIDで連絡先のコレクションを取得することができます。

private EntityCollection getContactByAccountId(IOrganizationService service, Guid accountId) 
    { 
     QueryExpression query = new QueryExpression("contact"); 
     query.ColumnSet = new ColumnSet(new string[] { "contactid", "fullname" }); 
     query.Criteria.AddCondition(new ConditionExpression("parentcustomerid", ConditionOperator.Equal, accountId)) 
     return service.RetrieveMultiple(query); 
    } 
+0

回答ありがとうございますが、変換エラーです。例えば、私はGetとErrorが 'entityreference'に' entitycollection'を変換できない – transformer

+0

EntityCollection型のOut putパラメータを使うことができると思います。 [Output( "Contacts")] [ReferenceTarget( "contact")] 公開OutArgument 連絡先{get;セット; }。 そして、明らかにentityCollectionオブジェクトをentityReferenceに設定することはできません。 –

関連する問題