locked
ActivityParty won't set on Online RRS feed

  • Question

  • Hi!

    I'm trying to migrate data from MS Dynamics CRM On Premise 2011 (5.0) to Online (Spring '14).

    At this point I'm stuck with the Activity-entities. I can get the entities to Online, but the ActivityParty won't get along, the 'From', 'To', 'Cc' etc. fields are empty. I map the whole entity, for example 'Email', in my tool, but when I create it with the OrganizationService, it won't get to Online.

        public class EmailBuilder : BuilderBase
        {
            private Email result;
            private ActivityPointerBase emailBase;
    
            public EmailBuilder(OrganizationServiceProxy proxy, CRMContainer dataContext, AccountContext accountContext, ActivityPointerBase emailBase, Guid ownerID) 
                : base(dataContext, accountContext)
            {
                this.result = new Email();
                this.result.OwnerId = this.BuildOwnerId(ownerID);
                this.emailBase = emailBase;
            }
    
    
            public override Microsoft.Xrm.Sdk.Entity GetResult()
            {
                return result;
            }
    
            public override void Build()
            {
                this.result.ActivityId = emailBase.ActivityId;
                this.result.ActualEnd = emailBase.ActualEnd;
                this.result.ActualStart = emailBase.ActualStart;
    
                List<ActivityPartyBase> activityParties = new List<ActivityPartyBase>();
    
                activityParties = partyRepository.GetActivityPartiesById(emailBase.ActivityId);
    
                //Activity.From is mapped here
                //IEnumerable<ActivityPartyBase> activitypartybasesFrom = new List<ActivityPartyBase>();
                //activitypartybasesFrom = activityParties.Where(x => x.ParticipationTypeMask == (int)ParticipationTypeMask.SenderFrom);
                //if (activitypartybasesFrom != null)
                //{
                //    List<ActivityParty> fromparties = new List<ActivityParty>();
    
                //    foreach (ActivityPartyBase item in activitypartybasesFrom)
                //    {
                //        ActivityParty activityParty = new ActivityParty
                //        {
                //            PartyId = new EntityReference(SystemUser.EntityLogicalName, emailBase.OwnerId)
                //        };
                //        activityParty.ActivityId = new EntityReference(ActivityParty.EntityLogicalName, item.ActivityId);
                //        activityParty.ActivityPartyId = item.ActivityPartyId;
                //        activityParty.AddressUsed = item.AddressUsed;
    
                //        activityParty.ParticipationTypeMask = new OptionSetValue(item.ParticipationTypeMask);
                //        if (item.PartyId.HasValue)
                //        {
                //            activityParty.PartyId = new EntityReference(ActivityParty.EntityLogicalName, item.PartyId.Value);
                //        }
                //            fromparties.Add(activityParty);
                //    }
    
                //        //this.result.From = fromparties;
                //} 
                //
    
                //Activity.To is mapped here
                IEnumerable<ActivityPartyBase> activitypartybasesTo = new List<ActivityPartyBase>();
                activitypartybasesTo = activityParties.Where(x => x.ParticipationTypeMask == (int)ParticipationTypeMask.ToRecipient);
                if (activitypartybasesTo != null)
                {
                    List<ActivityParty> toparties = new List<ActivityParty>();
    
                    foreach (ActivityPartyBase item in activitypartybasesTo)
                    {
                        ActivityParty activityParty = new ActivityParty();
                        activityParty.ActivityId = new EntityReference(ActivityParty.EntityLogicalName, item.ActivityId);
                        activityParty.ActivityPartyId = item.ActivityPartyId;
                        activityParty.AddressUsed = item.AddressUsed;
                        activityParty.ParticipationTypeMask = new OptionSetValue(item.ParticipationTypeMask);
                        activityParty.LogicalName = "activityparty";
                        activityParty.Id = new Guid();
                        activityParty.ActivityPartyResourceSpec = new ResourceSpec();
                        if (item.PartyId != null)
                        {
                            activityParty.PartyId = new EntityReference(ActivityParty.EntityLogicalName, (item.PartyId).GetValueOrDefault());
                        }
    
    
                        toparties.Add(activityParty);
                    }
                    this.result.To = toparties;
                }
                //
    
                //Activity.Cc is mapped here
                IEnumerable<ActivityPartyBase> activitypartybaseCcRecipients = new List<ActivityPartyBase>();
                ActivityPartyBase partyBase = new ActivityPartyBase();
                partyBase = activityParties.First(x => x.ParticipationTypeMask == (int)ParticipationTypeMask.SenderFrom);
    
                ActivityParty activityParty1 = new ActivityParty();
                activityParty1.ActivityId = new EntityReference(ActivityParty.EntityLogicalName, partyBase.ActivityId);
                activityParty1.ActivityPartyId = partyBase.ActivityPartyId;
                activityParty1.AddressUsed = partyBase.AddressUsed;
                activityParty1.ParticipationTypeMask = new OptionSetValue(partyBase.ParticipationTypeMask);
               }
    
    
                    //this.result.From = new ActivityParty[] { activityParty1 };
                //this.result.email_activity_parties = ccparties; 
                
    
                //Activity.Bcc is mapped here
                IEnumerable<ActivityPartyBase> activitypartybaseBccRecipients = new List<ActivityPartyBase>();
                activitypartybaseBccRecipients = activityParties.Where(x => x.ParticipationTypeMask == (int)ParticipationTypeMask.BccRecipient);
    
                List<ActivityParty> bccparties = new List<ActivityParty>();
                foreach (ActivityPartyBase item in activitypartybaseBccRecipients)
                {
                    ActivityParty activityParty = new ActivityParty
                    {
                        PartyId = new EntityReference( SystemUser.EntityLogicalName, emailBase.OwnerId)
                    };
                    activityParty.ActivityId = new EntityReference(ActivityParty.EntityLogicalName, item.ActivityId);
                    activityParty.ActivityPartyId = item.ActivityPartyId;
                    activityParty.AddressUsed = item.AddressUsed;
                    activityParty.ParticipationTypeMask = new OptionSetValue(item.ParticipationTypeMask);
                    //if (item.PartyId != null)
                    //{
                    //    activityParty.PartyId = new EntityReference(ActivityParty.EntityLogicalName, (item.PartyId).GetValueOrDefault());
                    //}
    
                    bccparties.Add(activityParty);
                }
                this.result.Bcc = bccparties;
                //
    
    ////Mapping of loose attributes here////
    
            }

    I commented the other party-mappings out, just to check if a single mapping will do. When I debug it's working: the ActivityParty will set in the Email.

    Here where I retrieve it in my Builder:

                
    public override void Process(OrganizationServiceProxy proxy, CRMContainer dataContext, AccountContext accountContext)
            {            
                List<ActivityPointerBase> emailBases = new List<ActivityPointerBase>();
                emailBases = emailRepository.FetchAll((int)ActivityPointerType.Email);
    
                foreach (ActivityPointerBase emailBase in emailBases.Take(2))
                {
                EmailBuilder emailBuilder = new EmailBuilder(proxy, dataContext, accountContext, emailBase, ownerID);
                emailBuilder.Build();
                Email email = (Email)emailBuilder.GetResult();
                email.Id = proxy.Create(email);
                accountContext.emails.Add(email);
                }
    }

    Have any of you guys an idea of what I'm doing wrong? Any tips?

    Thanks in advance!!

    Wednesday, November 26, 2014 7:36 AM

All replies