Question Status

Verified
kandarp parikh asked a question on 11 Sep 2014 6:25 AM

This code is not working while inserting a record in the entity.

Entity objCRMAppointment=new Entity("appointment");
EntityReferenceCollection requiredAttendiesList = new EntityReferenceCollection();
for (int count = 0; count < objAppointment.RequiredAttendies.Length; count++)
{
if (objAppointment.RequiredAttendies[count].Trim() != string.Empty)
{
EntityReference requiredAttendies = new EntityReference(objAppointment.RequiredAttendies_type[count].Trim(), new Guid(objAppointment.RequiredAttendies[count].Trim()));
requiredAttendiesList.Add(requiredAttendies);
}
}
objCRMAppointment["requiredattendees"] = requiredAttendiesList;

Reply
Suggested Answer
Balamurali Srinivasagan responded on 11 Sep 2014 8:15 AM

Hi Kandarp,

You have to use ActivityParty class to define the Appointment’s Required Attendees.

***

//EntityReferenceCollection requiredAttendiesList = new EntityReferenceCollection();      List<ActivityParty> party = new List<ActivityParty>();      for (int count = 0; count < objAppointment.RequiredAttendies.Length; count++)      {          if (objAppointment.RequiredAttendies[count].Trim() != string.Empty)          {              EntityReference requiredAttendies = new EntityReference(objAppointment.RequiredAttendies_type[count].Trim(), new Guid(objAppointment.RequiredAttendies[count].Trim()));              //requiredAttendiesList.Add(requiredAttendies);              party.Add(new ActivityParty              {                  PartyId = requiredAttendies              });          }      }                    // Create the appointment instance.              Appointment appointment = new Appointment              {                  Subject = "Test Appointment",                  Description = "Test Appointment created using the BookRequest Message.",                  ScheduledStart = DateTime.Now.AddHours(1),                  ScheduledEnd = DateTime.Now.AddHours(2),                  Location = "Office",                  RequiredAttendees = party.ToArray(),                  Organizer = party.ToArray()              };              // Use the Book request message.              BookRequest book = new BookRequest              {                  Target = appointment              };              BookResponse booked = (BookResponse)_serviceProxy.Execute(book);              Guid _appointmentId = booked.ValidationResult.ActivityId;              // Verify that the appointment has been scheduled.              if (_appointmentId != Guid.Empty)              {                  Console.WriteLine("Succesfully booked {0}.", appointment.Subject);              }
***

Refer SDK sample code - http://msdn.microsoft.com/en-us/library/gg334289.aspx

If my post helped you please mark my post as the suggested answer.

Regards,
Balamurali

Reply
kandarp parikh responded on 11 Sep 2014 9:12 AM

Thanks for reply.

But, can we extend the ActivityParty from any of the namespace?

because none pf the namespace works of sdk.

Thnaks.

Reply
Verified Answer
Balamurali Srinivasagan responded on 11 Sep 2014 9:44 AM

Hi Kandarp,

The ActivityParty is an entity class when you use Early Binding. http://msdn.microsoft.com/en-us/library/gg328549.aspx. The previous code is based on Early binding.

Here is the modified code on late binding model.

                    //EntityReferenceCollection requiredAttendiesList = new EntityReferenceCollection();

                    //List<ActivityParty> party = new List<ActivityParty>(); // Early binding

                    List<Entity> party = new List<Entity>(); // late binding

                    for (int count = 0; count < objAppointment.RequiredAttendies.Length; count++)

                    {

                        if (objAppointment.RequiredAttendies[count].Trim() != string.Empty)

                        {

                            EntityReference requiredAttendies = new EntityReference(objAppointment.RequiredAttendies_type[count].Trim(), new Guid(objAppointment.RequiredAttendies[count].Trim()));

                            //requiredAttendiesList.Add(requiredAttendies);

                            //Early binding

                            //party.Add(new ActivityParty("activityparty")

                            //{

                            //    PartyId = requiredAttendies

                            //});

                            //Late binding

                            Entity activityparty = new Entity("activityparty");

                            activityparty["partyid"] = requiredAttendies;

                            party.Add(activityparty);

                        }

                    }

                    // Create the appointment instance.

                    //Appointment appointment = new Appointment

                    //{

                    //    Subject = "Test Appointment",

                    //    Description = "Test Appointment created using the BookRequest Message.",

                    //    ScheduledStart = DateTime.Now.AddHours(1),

                    //    ScheduledEnd = DateTime.Now.AddHours(2),

                    //    Location = "Office",

                    //    RequiredAttendees = party.ToArray(),

                    //    Organizer = party.ToArray()

                    //};

                    Entity appointment = new Entity("appointment");

                    appointment["subject"] = "Test Appointment";

                    appointment["description"] = "Test Appointment created using the BookRequest Message.";

                    appointment["scheduledstart"] = DateTime.Now.AddHours(1);

                    appointment["scheduledend"] = DateTime.Now.AddHours(2);

                    appointment["location"] = "Office";

                    appointment["requiredattendees"] = party.ToArray();

                    appointment["organizer"] = party.ToArray();

                    // Use the Book request message.

                    BookRequest book = new BookRequest

                    {

                        Target = appointment

                    };

                    BookResponse booked = (BookResponse)_serviceProxy.Execute(book);

                    Guid _appointmentId = booked.ValidationResult.ActivityId;

                    // Verify that the appointment has been scheduled.

                    if (_appointmentId != Guid.Empty)

                    {

                        Console.WriteLine("Succesfully booked {0}.", appointment["subject"]);

                    }

If my post helped you please mark my post as the suggested answer.

Regards,
Balamurali

 
Reply
Verified Answer
Aileen Gusni responded on 11 Sep 2014 10:14 AM

Hi Kandarp,

The Required Attendees, Optional Attendees, Organizer in Appointment in CRM are basically related to ActivityParty you should use special entity: ActivityParty

You can see this:

msdn.microsoft.com/.../hh372955.aspx

and this as example:

msdn.microsoft.com/.../gg334289.aspx

Just watch out these lines:

// Create the ActivityParty instance. is the key

                   ActivityParty party = new ActivityParty

                   {

                       PartyId = new EntityReference(SystemUser.EntityLogicalName, userResponse.UserId)

                   };

                   // Create the appointment instance.

                   Appointment appointment = new Appointment

                   {

                       Subject = "Test Appointment",

                       Description = "Test Appointment created using the BookRequest Message.",

                       ScheduledStart = DateTime.Now.AddHours(1),

                       ScheduledEnd = DateTime.Now.AddHours(2),

                       Location = "Office",

                       RequiredAttendees = new ActivityParty[] { party }, // key

                       Organizer = new ActivityParty[] { party }                        

                   };    

But, I notice that Balamuri has given you great example, using Early Bound and Late Bound..So just try it!

Thanks.

Reply
kandarp parikh responded on 12 Sep 2014 12:16 AM

Thanks Balamurali for your wonderful response. It's works as expected.

Thanks once again.

Reply
Verified Answer
Balamurali Srinivasagan responded on 11 Sep 2014 9:44 AM

Hi Kandarp,

The ActivityParty is an entity class when you use Early Binding. http://msdn.microsoft.com/en-us/library/gg328549.aspx. The previous code is based on Early binding.

Here is the modified code on late binding model.

                    //EntityReferenceCollection requiredAttendiesList = new EntityReferenceCollection();

                    //List<ActivityParty> party = new List<ActivityParty>(); // Early binding

                    List<Entity> party = new List<Entity>(); // late binding

                    for (int count = 0; count < objAppointment.RequiredAttendies.Length; count++)

                    {

                        if (objAppointment.RequiredAttendies[count].Trim() != string.Empty)

                        {

                            EntityReference requiredAttendies = new EntityReference(objAppointment.RequiredAttendies_type[count].Trim(), new Guid(objAppointment.RequiredAttendies[count].Trim()));

                            //requiredAttendiesList.Add(requiredAttendies);

                            //Early binding

                            //party.Add(new ActivityParty("activityparty")

                            //{

                            //    PartyId = requiredAttendies

                            //});

                            //Late binding

                            Entity activityparty = new Entity("activityparty");

                            activityparty["partyid"] = requiredAttendies;

                            party.Add(activityparty);

                        }

                    }

                    // Create the appointment instance.

                    //Appointment appointment = new Appointment

                    //{

                    //    Subject = "Test Appointment",

                    //    Description = "Test Appointment created using the BookRequest Message.",

                    //    ScheduledStart = DateTime.Now.AddHours(1),

                    //    ScheduledEnd = DateTime.Now.AddHours(2),

                    //    Location = "Office",

                    //    RequiredAttendees = party.ToArray(),

                    //    Organizer = party.ToArray()

                    //};

                    Entity appointment = new Entity("appointment");

                    appointment["subject"] = "Test Appointment";

                    appointment["description"] = "Test Appointment created using the BookRequest Message.";

                    appointment["scheduledstart"] = DateTime.Now.AddHours(1);

                    appointment["scheduledend"] = DateTime.Now.AddHours(2);

                    appointment["location"] = "Office";

                    appointment["requiredattendees"] = party.ToArray();

                    appointment["organizer"] = party.ToArray();

                    // Use the Book request message.

                    BookRequest book = new BookRequest

                    {

                        Target = appointment

                    };

                    BookResponse booked = (BookResponse)_serviceProxy.Execute(book);

                    Guid _appointmentId = booked.ValidationResult.ActivityId;

                    // Verify that the appointment has been scheduled.

                    if (_appointmentId != Guid.Empty)

                    {

                        Console.WriteLine("Succesfully booked {0}.", appointment["subject"]);

                    }

If my post helped you please mark my post as the suggested answer.

Regards,
Balamurali

 
Reply
Verified Answer
Aileen Gusni responded on 11 Sep 2014 10:14 AM

Hi Kandarp,

The Required Attendees, Optional Attendees, Organizer in Appointment in CRM are basically related to ActivityParty you should use special entity: ActivityParty

You can see this:

msdn.microsoft.com/.../hh372955.aspx

and this as example:

msdn.microsoft.com/.../gg334289.aspx

Just watch out these lines:

// Create the ActivityParty instance. is the key

                   ActivityParty party = new ActivityParty

                   {

                       PartyId = new EntityReference(SystemUser.EntityLogicalName, userResponse.UserId)

                   };

                   // Create the appointment instance.

                   Appointment appointment = new Appointment

                   {

                       Subject = "Test Appointment",

                       Description = "Test Appointment created using the BookRequest Message.",

                       ScheduledStart = DateTime.Now.AddHours(1),

                       ScheduledEnd = DateTime.Now.AddHours(2),

                       Location = "Office",

                       RequiredAttendees = new ActivityParty[] { party }, // key

                       Organizer = new ActivityParty[] { party }                        

                   };    

But, I notice that Balamuri has given you great example, using Early Bound and Late Bound..So just try it!

Thanks.

Reply
Suggested Answer
Balamurali Srinivasagan responded on 11 Sep 2014 8:15 AM

Hi Kandarp,

You have to use ActivityParty class to define the Appointment’s Required Attendees.

***

//EntityReferenceCollection requiredAttendiesList = new EntityReferenceCollection();      List<ActivityParty> party = new List<ActivityParty>();      for (int count = 0; count < objAppointment.RequiredAttendies.Length; count++)      {          if (objAppointment.RequiredAttendies[count].Trim() != string.Empty)          {              EntityReference requiredAttendies = new EntityReference(objAppointment.RequiredAttendies_type[count].Trim(), new Guid(objAppointment.RequiredAttendies[count].Trim()));              //requiredAttendiesList.Add(requiredAttendies);              party.Add(new ActivityParty              {                  PartyId = requiredAttendies              });          }      }                    // Create the appointment instance.              Appointment appointment = new Appointment              {                  Subject = "Test Appointment",                  Description = "Test Appointment created using the BookRequest Message.",                  ScheduledStart = DateTime.Now.AddHours(1),                  ScheduledEnd = DateTime.Now.AddHours(2),                  Location = "Office",                  RequiredAttendees = party.ToArray(),                  Organizer = party.ToArray()              };              // Use the Book request message.              BookRequest book = new BookRequest              {                  Target = appointment              };              BookResponse booked = (BookResponse)_serviceProxy.Execute(book);              Guid _appointmentId = booked.ValidationResult.ActivityId;              // Verify that the appointment has been scheduled.              if (_appointmentId != Guid.Empty)              {                  Console.WriteLine("Succesfully booked {0}.", appointment.Subject);              }
***

Refer SDK sample code - http://msdn.microsoft.com/en-us/library/gg334289.aspx

If my post helped you please mark my post as the suggested answer.

Regards,
Balamurali

Reply