Partager via


Changing the activityparty using a CRM Plugin

Hey there,

It's been a while, but I've been busy doing a lot of XRM stuff.

 

I wanted to share this piece of code with you since it has been a major headache of mine for a long time in a project, I've searched high and low and couldn't figure it out, so if it's any help to you, please leave me a comment.

 

It's all about changing activityparties in a meeting. Why would you that? Well if you've searched for this you probably have the reason yourself.

 

 private static List<ActivityParty> ActivityParties(XrmServiceContext xrm, Appointment appointment, string currentuserid)
        {
            string activityid = string.Empty;

            var reqAttendees = xrm.ActivityPartySet.Where(ap => ap.ActivityId.Id == appointment.ActivityId);
            List<ActivityParty> newRec = new List<ActivityParty>();
            foreach (var party in reqAttendees)
            {
                activityid = party.ActivityPartyId.ToString();
                var pUser = new EntityReference("systemuser", new Guid(currentuserid));
                if (party.PartyId.Id.ToString().ToLower() != pUser.Id.ToString().ToLower())
                {
                    ActivityParty reqNewAttendees = new ActivityParty { PartyId = new EntityReference("systemuser", party.PartyId.Id) };
                    newRec.Add(reqNewAttendees);
                }
            }
            return newRec;
        }