Iterating over requiredattendees in an appointment

In this sample code I will show you how to iterate over the requiredattandees attribute of an appointment. This  attribute is a list of activityparty records. An activityparty record can contain many different entity types, for example contacts and accounts:

//If you want to iterate over every appointment use a RetrieveMumltipleRequest
var appointment = proxy.Retrieve(Appointment.EntityLogicalName,new Guid("FC8C427B-26AE-E111-ADAD-000C29CBD80B"),new ColumnSet(true));
List<ActivityParty> party = ((Appointment)appointment).RequiredAttendees.ToList<ActivityParty>();
foreach (ActivityParty ap in party)
    //You can retrieve metadata about a contact or an account by performing a new request
    if(ap.PartyId.LogicalName == Contact.EntityLogicalName)
        Console.WriteLine(string.Format("It's a contact with id {0}",ap.PartyId.Id));
    else if (ap.PartyId.LogicalName == Account.EntityLogicalName)
        Console.WriteLine(string.Format("It's an account with id {0}", ap.PartyId.Id));

Comments are closed.