2014-11-11 2 views
0

다음 코드를 가지고 있으며 이에 대한 좀 더 우아한 접근 방법을 찾으려고합니다. activityParty는 DataCollection입니다. 기본적으로 전자 메일에 대한받는 사람 목록을 얻으려고 시도하고 있습니다.이 전자 메일은 유형 사용자 또는 연락처 일 수 있습니다.CRM Late Bound - Cleaner Approach

초기 바인딩에 익숙하지만이 시나리오에서는 후기 바인딩을 사용해야합니다.

더 나은 방법이 있습니까?

var recipientParty = activityParty.Where(x => x.GetAliasedValueOrDefault<OptionSetValue>("ap.participationtypemask").Value == 2).ToList(); 
var recipientList = new List<string>(); 

foreach (var to in recipientParty) 
{ 
    if (to.Attributes.Contains("u.internalemailaddress")) 
    { 
     recipientList.Add(to.GetAliasedValueOrDefault<string>("u.internalemailaddress")); 
    } 

    if (to.Attributes.Contains("c.emailaddress1")) 
    { 
     recipientList.Add(to.GetAliasedValueOrDefault<string>("c.emailaddress1")); 
    } 
} 
+0

이것이 도움이 될 수 있는지 확인 http://www.crmanswers.net/2014/09/getattributevalue-activityparty.html –

답변

0

이 시도 :

using (var serviceContext = new OrganizationServiceContext(this.OrganizationService)) // if you are writing custom code activity 
//using (var serviceContext = new OrganizationServiceContext(localContext.OrganizationService)) // if you are writing plugin 
{ 
    var activityPartySet = serviceContext.CreateQuery<ActivityParty>(); 
    var activityParties = activityPartySet.Where(
           ap => ap.PartyId != null && 
           ap.ParticipationTypeMask != null && 
           ap.ParticipationTypeMask.Value == 2).ToList(); 

    var userSet = serviceContext.CreateQuery<SystemUser>(); 
    var contactSet = serviceContext.CreateQuery<Contact>(); 
    var recipientList = new List<string>(); 
    foreach (var ap in activityParties) 
    { 
     var partyRef = ap.PartyId; 
     if (partyRef.LogicalName == SystemUser.EntityLogicalName) 
     { 
      var user = (from u in userSet 
         where u.Id == partyRef.Id 
         select new SystemUser 
         { 
          InternalEMailAddress = u.InternalEMailAddress 
         }).FirstOrDefault(); 

      if (user != null) 
       recipientList.Add(user.InternalEMailAddress); 
     } 
     else if (partyRef.LogicalName == Contact.EntityLogicalName) 
     { 
      var contact = (from c in contactSet 
          where c.Id == partyRef.Id 
          select new Contact 
          { 
           EMailAddress1 = c.EMailAddress1 
          }).FirstOrDefault(); 

      if (contact != null) 
       recipientList.Add(contact.EMailAddress1); 
     } 
    } 
} 

는 희망이 도움이!

+0

답변 주셔서 감사하지만 늦은 바운드를 사용하고 있습니다. – Andrew

0

엔티티의 AddressUsed 속성을 확인하십시오. 참여자의 출처가되는 엔티티와 상관없이 이메일 주소를 포함해야합니다.

그래서 코드에 {...} 대신 전체 to.AddressUsed을 사용할 수 있습니다.