Showing posts with label Activity Party. Show all posts
Showing posts with label Activity Party. Show all posts

Friday, May 24, 2013

Get Required Attendee(Activity Party) value from Appointment.


Guid Id = new Guid("D77839B3-CBC2-E211-8DC3-B4B52F6714CA");
            XrmServiceContext _context = new XrmServiceContext(_service);
            Appointment appointment = _context.AppointmentSet.Where(p=>p.ActivityId==Id).SingleOrDefault();
            if (appointment != null)
            {
               
                EntityCollection receipt = new EntityCollection();
                receipt = appointment.GetAttributeValue<EntityCollection>("requiredattendees");
                for (int i = 0; i < receipt.Entities.Count; i++)
                {
                    ActivityParty ap = receipt[i].ToEntity<ActivityParty>();

                    string id,name;

                    if (ap.PartyId.LogicalName == "account")
                    {
                        id = ap.PartyId.Id.ToString();
                        name = ap.PartyId.Name;
                    }
                    if (ap.PartyId.LogicalName == "contact")
                    {
                        id = ap.PartyId.Id.ToString();
                        name = ap.PartyId.Name;
                    }
                    if (ap.PartyId.LogicalName == "systemuser")
                    {
                        id = ap.PartyId.Id.ToString();
                        name = ap.PartyId.Name;
                    }
                }
            }