locked
How to create an appointment with attendees? RRS feed

  • Question

  • Hello,

    I'm having trouble creating an appointment with attendees. I'm also having a very hard time finding code samples on the Internet on how to do that. So far, I have managed to create an appointment with systemuser as attendees but for some strange reason it doesn't work with contacts. 

     

    This is the code I'm using:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim service As CrmService = Me.GetCRMService()
    
            Dim Appt As New appointment
            Dim party1 As New activityparty
            Dim party2 As New activityparty
    
            party1.partyid = New Lookup(EntityName.systemuser.ToString(), New Guid("6D642716-F24E-E011-962B-68B599B6548A"))
            party2.partyid = New Lookup(EntityName.contact.ToString(), New Guid("CDE3F195-0A53-E011-A2F9-68B599B6548A"))
    
            Dim Attendees As activityparty() = {party2}
    
            With Appt
                Appt.scheduledstart = CrmDateTime.FromUser(DateTime.Today)
                Appt.scheduledend = CrmDateTime.FromUser(DateTime.Today.AddMinutes(15))
                Appt.subject = "Test"
                Appt.ownerid = New Owner(EntityName.systemuser.ToString(), New Guid("6D642716-F24E-E011-962B-68B599B6548A"))
                Appt.requiredattendees = Attendees
            End With
    
            service.Create(Appt)
    
            MessageBox.Show("Ok")
        End Sub
    

     

    I keep getting 'server cannot process the request', I don't know why. If I only add party1 (systemuser), it works fine, but when I try to add party2 (contact), it fails. I just don't understand... All the Ids I'm using are valid in my database, I double-checked them in the database.

     

    Thank you for your help

     

     

     

     

     

    Tuesday, November 15, 2011 11:46 AM

Answers

  • Thank you David, that did help a lot!

    I was getting this error message: "Invalid Party Object Type 4007"

     

    And figured out that this was the problem:

    party2.partyid = New Lookup(EntityName.contact.ToString(), New Guid("CDE3F195-0A53-E011-A2F9-68B599B6548A"))
    

    And should have been replaced with this:

    party2.partyid = New Lookup("contact", New Guid("CDE3F195-0A53-E011-A2F9-68B599B6548A"))

     

    I just don't understand why EntityName.contact.ToString() does not work...

    • Marked as answer by Gnarl Thursday, November 17, 2011 10:59 AM
    Thursday, November 17, 2011 10:59 AM

All replies

  • Try removing the

     Appt.ownerid = New Owner(EntityName.systemuser.ToString(), New Guid("6D642716-F24E-E011-962B-68B599B6548A"))
     

    Wednesday, November 16, 2011 11:59 AM
  • I suggest you catch the Exception as a SoapException (as per http://msdn.microsoft.com/en-us/library/bb928443.aspx - your code looks like CRM 4 code) to get a more useful error message
    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Wednesday, November 16, 2011 5:00 PM
    Moderator
  • Thank you David, that did help a lot!

    I was getting this error message: "Invalid Party Object Type 4007"

     

    And figured out that this was the problem:

    party2.partyid = New Lookup(EntityName.contact.ToString(), New Guid("CDE3F195-0A53-E011-A2F9-68B599B6548A"))
    

    And should have been replaced with this:

    party2.partyid = New Lookup("contact", New Guid("CDE3F195-0A53-E011-A2F9-68B599B6548A"))

     

    I just don't understand why EntityName.contact.ToString() does not work...

    • Marked as answer by Gnarl Thursday, November 17, 2011 10:59 AM
    Thursday, November 17, 2011 10:59 AM