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

Notifications

Announcements

No record found.

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)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

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

  • prasy Profile Picture
    65 on at

    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)

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

    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

                         }

                       }

                   }

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

    Thanks Andrii Butenko. it worked.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans