[英]Dynamics CRM 2016 (Online) - Retrieve appointments
我正在嘗試使用LINQ查詢從CRM在線環境中檢索所有約會(我是編程的新手)。 獲取約會數據很容易,但是我也想檢索約會的必需與會者(這可以是一個帳戶,例如,聯系人),並從與會者那里獲取一些元數據(例如姓名,電子郵件地址)。 不幸的是,似乎無法做到這一點,並希望有人可以幫助我。
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();
}
我認為您不需要加入,因為您的查詢中已經有活動方ID。您可能在這里遇到了加入功能的限制。 這是一種方法:
foreach(var app in appointments)
{
var requiredAttendees = app.RequiredAttendees.ToList();
foreach(var ra in requiredAttendees)
{
// do whatever you want with each required attendee here, perform a separate retrieve for more details
}
}
我也意識到這是一個額外的步驟。 如果您想嘗試加入工作,建議您改用partyid。 如果要走那條路線,您可能需要嵌套查詢或更復雜的聯接,因為與ActivityParty的關系是1:N。 如果您只關心第一個必需的與會者,請查看此鏈接: https : //www.periscopedata.com/blog/4-ways-to-join-only-the-first-row-in-sql.html
解決了! 我確實使用布倫登的方法來完成它。 首先,我查詢了所有約會,
這是我的代碼:
public AppointmentData[] RetrieveAppointments(bool persistChange)
{
var appointmentData = new List<AppointmentData>();
using (var context = new FmServiceContext(_service))
{
//First we get all relevant appointments
var appointments = (from app in context.AppointmentSet
where app.StateCode != 0
select new { app});
foreach (var appointment in appointments)
{
//we loop all the returned attendees of the appointments
var attendees = new List<Attendee>();
foreach (var attendee in appointment.app.RequiredAttendees)
{
if (attendee.PartyId != null)
{
//if an attendee is an account
if (attendee.PartyId.LogicalName == "account")
{
var account = (from acc in context.AccountSet
where acc.AccountId == attendee.PartyId.Id
select new {acc});
}
//add the attendee
{
attendees.Add(new Attendee
{
// get additional metadata of the attendee
});
}
appointmentData.Add(new AppointmentData
{
Attendees = attendees,
// get additional metadata of the appointment
});
}
}
}
return appointmentData.ToArray();
}
}
}
結果是:約會列表以及該約會所需的與會者列表。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.