繁体   English   中英

Dynamics CRM 2016(在线)-检索约会

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM