Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Hot get Aggregate attribute Id and Name in plugin

(0) ShareShare
ReportReport
Posted on by 379

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

  • Suggested answer
    Ray Profile Picture
    Ray 1,469 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.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans