Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Getting error while trying to make connection record between account and contact

(0) ShareShare
ReportReport
Posted on by 6

Hello All Experts,

I am using below code to create connection between account and contact .

Connection newConnection = new Connection
{
Record1Id = new EntityReference(Account.EntityLogicalName, accountRef.Id),
Record1RoleId = new EntityReference(ConnectionRole.EntityLogicalName,(Guid)_connectionRoleId[0]),
Record2RoleId = new EntityReference(ConnectionRole.EntityLogicalName, (Guid)_connectionRoleId[0]),
Record2Id = new EntityReference(Contact.EntityLogicalName,entityContact.Id)
};
var _connectionId = context.OrganizationService.Create(newConnection);

this always gives an error as below


The record type 2 is not defined for use with the connection role 7ad04eae-5580-e411-9407-005056922296.

and when i try to comment either of the below line of code then record is getting created but Role To field is empty in Associated connection view grid.

Record1RoleId = new EntityReference(ConnectionRole.EntityLogicalName,(Guid)_connectionRoleId[0]),
Record2RoleId = new EntityReference(ConnectionRole.EntityLogicalName, (Guid)_connectionRoleId[0]),

any help will be appreciable.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Getting error while trying to make connection record between account and contact

    The new thread you created is the logical extension of your initial question that I believe was answered by Wahaj but was not marked as an answer. So either close the initial thread marking the answer and create the new thread or keep the conversation in the same thread.

  • EmployeeOcta Profile Picture
    6 on at
    RE: Getting error while trying to make connection record between account and contact

    I thought this query is different so not getting reply on that so created different thread.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Getting error while trying to make connection record between account and contact

    Please, don't create new threads that continue the other thread.

  • EmployeeOcta Profile Picture
    6 on at
    How to get matching connection role from connection role record

    Hi All i need to retrieve matching connection role based on roleid using c# code in plugin,

    is it possible to do that.

  • EmployeeOcta Profile Picture
    6 on at
    RE: Getting error while trying to make connection record between account and contact

    Hi Wahaj,

    I think you are absolutely correctly , i did a mistake in this .

    what i need is i am getting the list of roles which are associated with account , but also i need to get list of roles which are with contact but based on account role in my above code.

    e.g if there is a Role enabled for account is AssistantFor the there is another role Assistant for contact.

    if you could help me if i could get that contact role based on account role.

  • EmployeeOcta Profile Picture
    6 on at
    RE: Getting error while trying to make connection record between account and contact

    Hello All,

    In our scenario. i need to create a new contact record that will associated with the account with some connection  role.

    Also as per your suggestion if i do not assign the connectionroleid then name field is empty.

    How to achieve that i am not sure.

  • Verified answer
    Wahaj Rashid Profile Picture
    11,321 on at
    RE: Getting error while trying to make connection record between account and contact

    Hi,

    As per your code, you are assigning same role to both the Account and the Contact.

    If you wish to assign same role to both, you have to enable it for Account also. Or you can leave the Record1RoleId empty (null), its optional.

    Your code will look like this:

    Connection newConnection = new Connection
    {
    Record1Id = new EntityReference(Account.EntityLogicalName, accountRef.Id),
    Record2RoleId = new EntityReference(ConnectionRole.EntityLogicalName, (Guid)_connectionRoleId[0]),
    Record2Id = new EntityReference(Contact.EntityLogicalName,entityContact.Id)
    };
    var _connectionId = context.OrganizationService.Create(newConnection);

    But you need to find out what is the business scenario here? Let me explain.

    When you create a Connection between 2 records, you choose the roles from both end.

    For example:

    I create a connection on the Account with a Contact:

    • Connect To: John Doe (contact) (filed: Record2Id)
    • Role: Employee (field: Record2RoleId)
    • Connected From: ABC Company (Record1Id)
    • Role: Employer (field: Record1RoleId)

    Another example could be John Doe is an Contactor to ABC Company. And ABC Company is Business to John Doe.

    You need to decide which roles to assign (From and To) as per you requirement.

    Again Record1RoleId can be skipped, but review your requirements.

  • EmployeeOcta Profile Picture
    6 on at
    RE: Getting error while trying to make connection record between account and contact

    Hi All,

    I have checked the steps mentioned by Wahaj Rashid. and find the role can be connected to the contact .

    do i need to make the roles available for contact and account both or how is it?

    also my code writing is correct or not correct?

  • Verified answer
    Wahaj Rashid Profile Picture
    11,321 on at
    RE: Getting error while trying to make connection record between account and contact

    Hi,

    Please note, not all roles can be associated with Account or Contact.

    Please make sure, the connection role  7ad04eae-5580-e411-9407-005056922296  is allowed to be associated with Account and Contact entity.

    You can check this in the connection role properties, here are the steps:

    • Go to Advanced Settings -> Business Management -> Connection Roles.
    • Open the connection role (the one you are working with).
    • Review the configuration under Select record types:

    pastedimage1616409433008v1.png

    For more details, see this:

    https://docs.microsoft.com/en-us/powerapps/maker/data-platform/configure-connection-roles#create-a-connection-role

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans