Solved

Attached Contact to Account

Posted on 2012-03-29
2
424 Views
Last Modified: 2012-04-16
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
Comment
Question by:Kevin Robinson
2 Comments
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 500 total points
ID: 37787056
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
 
LVL 3

Author Closing Comment

by:Kevin Robinson
ID: 37850211
Thanks
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Sep 22nd 2014 Microsoft released Update Rollup 1 for Microsoft Dynamics CRM 2013 Service Pack 1 and back in July Update Rollup 3 was released.  So we now have:   Update Rollup 1Update Rollup 2Update Rollup 3Service Pack 1Update Rollup 1 for S…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question