Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to Retrieve Contact Connection and Connection Roles CRM 2013 using C#

Posted on by 65

Hello All,

I am working on Custom Workflow activity using C# , I need to retrieve Contact Connection data and Contact Connection Roles.

the connection form has some Connected To fields and Role To fields which i need to add to another Entity Dynamically

please help

*This post is locked for comments

  • prasy Profile Picture
    prasy 65 on at
    RE: How to Retrieve Contact Connection and Connection Roles CRM 2013 using C#

    Thanks Andrii Butenko. it worked.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to Retrieve Contact Connection and Connection Roles CRM 2013 using C#

    So to get name and role you should use something like

    var name = en.GetAttributeValue<EntityReference>("record2id").Name;

    var role = en.Contains("record2roleid") ? en.GetAttributeValue<EntityReference>("record2roleid").Name : null;

  • prasy Profile Picture
    prasy 65 on at
    RE: How to Retrieve Contact Connection and Connection Roles CRM 2013 using C#

    Thanks Andrii Butenko

    so, from below code how can i get contact name and Contact connection Role

    May be i am looking the results in wrong way...to retrieve contact name and contact Role connection

    if (results.Entities.Any())

               {

                   foreach (Entity en in results.Entities)

                   {                        

                           if (en.Contains("record2id"))

                          {

                                 ///How to get contact name  and contact role

                         }

                       }

                   }

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to Retrieve Contact Connection and Connection Roles CRM 2013 using C#

    Try to use something like:

              var query = new QueryExpression("connection");

              query.Criteria.AddCondition(new ConditionExpression("record1id", ConditionOperator.Equal, parentId));

              query.ColumnSet = new ColumnSet(true);

              var results = service.RetrieveMultiple(query);

    In resulting query record2id, record2roleid will contain information about connected records.

  • prasy Profile Picture
    prasy 65 on at
    RE: How to Retrieve Contact Connection and Connection Roles CRM 2013 using C#

    Yes, i did tired using the below code but it is not working

           

               var query = new QueryExpression("connection");
    
               query.Criteria.AddCondition(new ConditionExpression("record1id", ConditionOperator.Equal, parentId));
    
               query.ColumnSet = new ColumnSet(true);
    
               var results = service.RetrieveMultiple(query);

    I get below error 

    Unhandled Exception: Microsoft.Crm.CrmException: Unexpected exception from plug-in (Execute): xyzCustom.Connectionassign: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
    at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)
    at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to Retrieve Contact Connection and Connection Roles CRM 2013 using C#

    Hello,

    So what's not clear for you? How to retrieve connections for particular contact?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans