Solved

Attached Contact to Account

Posted on 2012-03-29
2
423 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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is a walkthrough guide I wrote whilst upgrading my on-premise MS Dynamics CRM 3.0 deployment to 4.0. This covers the actual installation of the product to a working level for my system, I ran into a lot of issues that the steps below fixed so h…
Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now