I'm trying to retrieve all the appointments from our CRM online environment using a LINQ query (I'm a newbie with programming). Getting the appointment data is easily done but I also want to retrieve the Required Attendees for the appointments (this could be an account, contact e.g) and fetch some Metadata (like the Name, E-mailadress for example) from the attendees. Unfortunately it seems impossible to get this done and was hoping someone could help me with this.
public AppointmentData[] RetrieveActivities(bool persistChange)
{
var appointmentData = new List<AppointmentData>();
using (var context = new FmServiceContext(_service))
{
var appointments = (from app in context.AppointmentSet
join a in context.AccountSet on app.Account_Appointments.AccountId equals a.AccountId
where app.StateCode != 0
select new {app, a});
foreach (var apappointments in appointments)
{
appointmentData.Add(new AppointmentData
{
//this should be the list of required attendees
RequiredAttendees = new ActivityParty[]
{
Attendeename = apappointments.a.Name
},
//Appointment data
AppointmentType = apappointments.app.fm_Typeafspraak == null ? null : DataHelper.GetOptionSetValueLabel(apappointments.app.LogicalName, "fm_typeafspraak", apappointments.app.fm_Typeafspraak.Value, _service),
Subject = apappointments.app.Subject,
StartDate = apappointments.app.ScheduledStart,
EndDate = apappointments.app.ScheduledEnd,
Duration = apappointments.app.ScheduledDurationMinutes,
Location = apappointments.app.Location,
Description = apappointments.app.Description,
Priority = apappointments.app.PriorityCode == null ? null : DataHelper.GetOptionSetValueLabel(apappointments.app.LogicalName, "prioritycode", apappointments.app.PriorityCode.Value, _service),
Status = apappointments.app.StateCode.ToString()
});
}
}
return appointmentData.ToArray();
}