locked
Generating "Contact To Contact" Relationships through the CRM webservice RRS feed

  • 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

    My Blog

    CRM Consultant for KMS Software
    Monday, August 10, 2009 10:38 AM

Answers

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

    My Blog

    CRM Consultant for KMS Software
    Tuesday, 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 role

    off 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
    1. Just to help you more, here is the code in vb.net. i hope it will help you.

      Dim
      objRelationship As New customerrelationship()
    2. 'Primary
    3. objRelationship.customerroleid = New Lookup()
    4. objRelationship.customerroleid.type = EntityName.relationshiprole.ToString()
    5. ' specify the id of the customer role here
    6. objRelationship.customerroleid.Value = New Guid("")
    7. objRelationship.customerid = New Customer()
    8. objRelationship.customerid.type = EntityName.contact.ToString()
    9. objRelationship.customerid.Value = New Guid(ContactID)

     

    1. objRelationship.partnerroleid = New Lookup()
    2. objRelationship.partnerroleid.type = EntityName.relationshiprole.ToString()
    3. ' specify the id of the partner role here
    4. objRelationship.partnerroleid.Value = New Guid("")
    5.  
    6. objRelationship.partnerid = New Customer()
    7. objRelationship.partnerid.type = EntityName.contact.ToString()
    8. objRelationship.partnerid.Value = New Guid(ContactID)

     

    1. Dim objService As CrmService = GetService()
    2. objService.Create(objRelationship)
    Tuesday, August 11, 2009 7:48 AM
  • 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 error

    Jonathan Nachman MBSP, MCTS

    My Blog

    CRM Consultant for KMS Software
    Tuesday, 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.

     

    Tuesday, August 11, 2009 7:58 AM