Answered by:
Generating "Contact To Contact" Relationships through the CRM webservice

Question
-
Im having diffuculty getting the relationship produces - its in VB.net ( i know, but im adding to an existing solution ) - My code is below...... the aim is to create a relationship and only fill in the relationship role on one side of the relationship (i.e no partnerroleid etc) - this is generating a useless exception and is not hitting the trace files.
code as follows
Try Dim cRelation As New customerrelationship() Dim contactlookup As New Customer contactlookup.type = EntityName.contact.ToString contactlookup.Value = New Guid(""GUID"") cRelation.customerid = contactlookup Dim personnel As New Customer personnel.type = EntityName.contact.ToString personnel.Value = New Guid("GUID") cRelation.partnerid = personnel 'HardCoded Dim role As Lookup role.type = EntityName.relationshiprole.ToString() role.Value = New Guid("GUID") cRelation.customerroleid = role service.Create(cRelation) Catch ex As Exception MsgBox(ex.ToString()) End Try End Sub
Jonathan Nachman MBSP, MCTS
CRM Consultant for KMS SoftwareMonday, August 10, 2009 10:38 AM
Answers
-
Here is an article on how to do this with UI
http://www.microsoft.com/dynamics/crm/using/sales/relationshiproles.mspx
As you can see even from UI you have to specify the role of both partner and the customer. You can get the role id by pressing ctrl+N in the relationship role window and opening it in the browser.
Also make sure the Role is valid for Contact to Contact Relationship as seen in the above microsoft article.
I hope it helps.
- Marked as answer by DavidJennawayMVP, Moderator Friday, August 21, 2009 8:43 AM
Tuesday, August 11, 2009 7:58 AM
All replies
-
HI Jonathan,
THe following code should work. It is in C# but i hope you can make it into vb.
where customerroleid and partnerroleid, you can reterive from "relationshiprole " role class.
customerrelationship objRelationship = new customerrelationship();//Primary
objRelationship.customerroleid = new Lookup();
objRelationship.customerroleid.type = EntityName.relationshiprole.ToString();
// specify the id of the customer role here
objRelationship.customerroleid.Value = new Guid(FindRole(lstRoles, "Primary Buyer").Value);objRelationship.customerid = new Customer();
objRelationship.customerid.type = EntityName.contact.ToString();
objRelationship.customerid.Value = new Guid(objPrimaryBuyer.ContactID);objRelationship.partnerroleid = new Lookup();
objRelationship.partnerroleid.type = EntityName.relationshiprole.ToString();
// specify the id of the partner role here
objRelationship.partnerroleid.Value = new Guid(FindRole(lstRoles,"Secondary Buyer").Value);objRelationship.partnerid = new Customer();
objRelationship.partnerid.type = EntityName.contact.ToString();
objRelationship.partnerid.Value = new Guid(objSecondaryBuyer.ContactID);CrmService objService = GetService();
objService.Create(objRelationship);
I hope it helps you.- Edited by Muhammad Ali Khan Monday, August 10, 2009 3:36 PM Just add some more details for better help
- Proposed as answer by Muhammad Ali Khan Monday, August 10, 2009 5:17 PM
Monday, August 10, 2009 3:32 PM -
I cant see a difference in my code! well apart from me only having a role specified on one side!
Jonathan Nachman MBSP, MCTS
CRM Consultant for KMS SoftwareTuesday, August 11, 2009 7:36 AM -
Hi Jonthan,
If you see the code, i also have specified the role. In your code you are adding the customerid, but you are not specifiying the role of teh customer in the relationship.
To be very exact, these lines are missing in your code.
//Primary
objRelationship.customerroleid = new Lookup();
objRelationship.customerroleid.type = EntityName.relationshiprole.ToString();
// specify the id of the customer role here
objRelationship.customerroleid.Value = new Guid(""); // here paste the guid of the relationship roleoff course you have already done the part below
objRelationship.customerid = new Customer();
objRelationship.customerid.type = EntityName.contact.ToString();
objRelationship.customerid.Value = new Guid(objPrimaryBuyer.ContactID);as you can see for the customer role id i have supplied the type as relationshiprole and id of the role is the relationship role id.
Let me know if it clears your confusion ?
Tuesday, August 11, 2009 7:44 AM -
- Just to help you more, here is the code in vb.net. i hope it will help you.
Dim objRelationship As New customerrelationship() - 'Primary
- objRelationship.customerroleid = New Lookup()
- objRelationship.customerroleid.type = EntityName.relationshiprole.ToString()
- ' specify the id of the customer role here
- objRelationship.customerroleid.Value = New Guid("")
- objRelationship.customerid = New Customer()
- objRelationship.customerid.type = EntityName.contact.ToString()
- objRelationship.customerid.Value = New Guid(ContactID)
- objRelationship.partnerroleid = New Lookup()
- objRelationship.partnerroleid.type = EntityName.relationshiprole.ToString()
- ' specify the id of the partner role here
- objRelationship.partnerroleid.Value = New Guid("")
- objRelationship.partnerid = New Customer()
- objRelationship.partnerid.type = EntityName.contact.ToString()
- objRelationship.partnerid.Value = New Guid(ContactID)
- Dim objService As CrmService = GetService()
- objService.Create(objRelationship)
- Proposed as answer by Muhammad Ali Khan Tuesday, August 11, 2009 1:45 PM
Tuesday, August 11, 2009 7:48 AM - Just to help you more, here is the code in vb.net. i hope it will help you.
-
I have the role in there already for the customer
'HardCoded Dim role As Lookup role.type = EntityName.relationshiprole.ToString() role.Value = New Guid("GUID") cRelation.customerroleid = role
I just dont have one for the partnerrole id , however when i specify one i still get an errorJonathan Nachman MBSP, MCTS
CRM Consultant for KMS SoftwareTuesday, August 11, 2009 7:52 AM -
can you try the vb.net code i have pasted you.
you have specify the role of both the customer and the partner. along with the role id of each.
Tuesday, August 11, 2009 7:54 AM -
Here is an article on how to do this with UI
http://www.microsoft.com/dynamics/crm/using/sales/relationshiproles.mspx
As you can see even from UI you have to specify the role of both partner and the customer. You can get the role id by pressing ctrl+N in the relationship role window and opening it in the browser.
Also make sure the Role is valid for Contact to Contact Relationship as seen in the above microsoft article.
I hope it helps.
- Marked as answer by DavidJennawayMVP, Moderator Friday, August 21, 2009 8:43 AM
Tuesday, August 11, 2009 7:58 AM