2016-06-23 11 views
0

CRMのオンライン環境からLINQクエリを使用してすべての予定を取得しようとしています(私はプログラミングの初心者です)。予定データを取得するのは簡単ですが、予定の必須出席者(これはアカウント、連絡先など)を取得し、出席者からメタデータ(名前、Eメールアドレスなど)を取得したい場合もあります。残念ながら、これを行うことは不可能と思われ、誰かが私を助けてくれることを望んでいました。Dynamics CRM 2016(オンライン) - 予定の取得

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(); 
    } 

答えて

0

あなたのアクティビティの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 

    } 
} 

また、これは追加手順であることを認識しています。あなたの参加を働かそうとしたいのであれば、代わりにパーティーに行くことをお勧めします。そのルートに行く場合は、ActivityPartyとの関係が1:Nであるため、ネストされたクエリまたはより複雑な結合が必要な場合があります。最初に必要な出席者だけが気になる場合は、このリンクをご覧ください:

0

解決済み!私はそれを行うためにBrendonのアプローチを使用しました。

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(); 
     } 
    } 
} 

結果:その任命のために必要な参加者のリストとのアポイントメントのリストまず、私はすべての予定を照会、
はここに私のコードです。

関連する問題