Qwark
Qwark

Reputation: 486

Account Contact Relationship in MS Dynamics CRM

How do I apply a contact to an account?

So I have an account and a contact

Account acc = new Account{Name="Ab..",};

Contact co = new Contact{Name="John", ..};

And then

CreateOneToManyRequest createOneToManyRelationshipRequest =
                        new CreateOneToManyRequest
{
   OneToManyRelationship = new OneToManyRelationshipMetadata
   {
       //What should I put here?
   },
   Lookup = new LookupAttributeMetadata
   {
       //And here?
   }
};
CreateOneToManyResponse createOneToManyRelationshipResponse =
                        (CreateOneToManyResponse)_serviceProxy.Execute(
                        createOneToManyRelationshipRequest);

Are I on the right track? or is there some other way of connecting contacts to accounts?

Upvotes: 4

Views: 1989

Answers (1)

TeaDrivenDev
TeaDrivenDev

Reputation: 6629

CreateOneToManyRequest is used to create a new relationship between entities (not records), i.e. change the database schema. I take it this is not what you want to do.

To attach a specific contact record to an account, set its parentcustomerid property. Thîs will be an EntityReference or Lookup or the like and take the ID and type ("account") of the 1 side of that 1:n relationship.

Upvotes: 5

Related Questions