Skip to main content

Notifications

Dynamics 365 Community / Forums / Sales forum / Hot get Aggregate attr...
Sales forum
Suggested answer

Hot get Aggregate attribute Id and Name in plugin

Posted on by 359

Hi,

I have a c# plugin, where I am using an aggregate fetch, and I have applied the groupBy property to a lookup attribute, now I need to retrieve the Id and Name of the group by records.

My fetch

pastedimage1681458958559v5.png

In this SS, I have highlighted the line number 103 attribute, which is the lookup attribute and Now I need to retrieve this attribute id and name.

I have run this fetch through the fetch xml tester, you can see the SS below, here I am able to seen both values "Id" and "RecordsName". So like this I need to get the Id's and records name through my plugin code.

pastedimage1681458877203v4.png

Categories:
  • Suggested answer
    Ray Profile Picture
    Ray 1,466 on at
    RE: Hot get Aggregate attribute Id and Name in plugin

    Hi Himanshu,

    Here is a sample code for you:

    var fetchXml = @"
                      
                        
                          
                        
                      
                    ";
    var results = OrgService.RetrieveMultiple(new FetchExpression(fetchXml));
    if (results.Entities.Any())
    {
        // use the attribute alias to get the attribute
        var owerAlias = results.Entities.First().GetAttributeValue("aliasownerid");
        if(owerAlias != null && owerAlias.Value != null)
        {
            // convert AliasedValue to actual attribute type
            var owerRef = (EntityReference)owerAlias.Value;
            var id = owerRef.Id;
            var name = owerRef.Name;
        }
    }

    You can replace the fetchXml with yours and follow the other code to get the attribute you want.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,186 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans