web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
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

I have the same question (0)
  • prasy Profile Picture
    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
    84,331 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
    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
    84,331 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
    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
    84,331 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans