• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

Attached Contact to Account

I ma using the code below to add a new contact and attach it to an account.  The contact gets added OK but the parentcustomerid does not seem to get added.


 
Private Function AddNewContact(ParentAccount As Guid, ParentAccountName As String, Firstname As String, Lastname As String, Email As String, Tel As String) As Guid

        Dim newcontact As New Entity()
        newcontact.LogicalName = "contact"

        Dim newcontactColl As New AttributeCollection()
        newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomeridtype", 1))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomeridname", "parentcustomerid"))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomerid", ParentAccount))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("firstname", Firstname))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("lastname", Lastname))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("telephone1", Tel))
        newcontactColl.Add(New KeyValuePair(Of String, Object)("emailaddress1", Email))
        newcontact.Attributes = newcontactColl

        Dim ContactID As Guid
        ContactID = Client.Create(newcontact)

        Return ContactID

    End Function

Open in new window

0
Kevin Robinson
Asked:
Kevin Robinson
1 Solution
 
Chinmay PatelEnterprise ArchitectCommented:
Hi VolunteerDevelopmentAgency,

newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomeridtype", 1))
newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomeridname", "parentcustomerid"))
newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomerid", ParentAccount))

Open in new window

               

I think it should be like this
newcontactColl.Add(New KeyValuePair(Of String, Object)("parentcustomerid", new EntityReference("account", parentcustomerid)))

Open in new window


If this code does not work then sorry as I am not comfortable with VB.Net, I have provided a C# style code.

Regards,
Chinmay.
0
 
Kevin RobinsonAuthor Commented:
Thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now