Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How get all related records field "regarding"

Posted on by Microsoft Employee

Hello.

In CRM 2016 on account is a view with all activities and related records fields "regarding".

How to get this list in SQL or C#:

0407.regarding.png

This code return only 7 records. How get all 42 records?

QueryExpression query = new QueryExpression { EntityName = "activitypointer", ColumnSet = new ColumnSet(new string[] { "activitytypecode" }) };
query.Criteria.AddCondition("regardingobjectid", ConditionOperator.Equal, Guid.Parse("35D2EE25-BE37-E211-AA69-00155D644201"));
EntityCollection collection = service.RetrieveMultiple(query);

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How get all related records field "regarding"

    This is it, but I added a condition on "is regular activity" and I have exactly what I needed. Thank you very much :)

    Criteria =
    {
        FilterOperator = LogicalOperator.And,
        Conditions =
        {
            new ConditionExpression("isregularactivity", ConditionOperator.Equal, true)
        }
    }


  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How get all related records field "regarding"

    Then try RollupRequest - I believe this is what you're looking for:

                var rollupRequest = new RollupRequest()
                {
                    RollupType = RollupType.Extended,
                    Query = new QueryExpression
                    {
                        EntityName = "activitypointer",
                        ColumnSet = new ColumnSet(new string[] { "activitytypecode" })
                    },
                    Target = new EntityReference("account", Guid.Parse("35D2EE25-BE37-E211-AA69-00155D644201"))
                };
    
                var rollupResonse = (RollupResponse)service.Execute(rollupRequest);
                var records = rollupResonse.EntityCollection.Entities;


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How get all related records field "regarding"

    Unfortunately, this command only returned 12 records.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How get all related records field "regarding"

    Hello,

    Try to use following code:

                QueryExpression query = new QueryExpression
                {
                    EntityName = "activitypointer",
                    ColumnSet = new ColumnSet(new string[] { "activitytypecode" }),
                    Distinct = true
                };
    
                var link = query.AddLink("activityparty", "activityid", "activityid");
                link.LinkCriteria.AddCondition("partyid", ConditionOperator.Equal, Guid.Parse("35D2EE25-BE37-E211-AA69-00155D644201"));
                EntityCollection collection = service.RetrieveMultiple(query);
    


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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans