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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

How to sort the entity collection order by descending of created on date in plugin.

(0) ShareShare
ReportReport
Posted on by

We have a requirement where we need to sort the entity collection in descending order by date in plugin . Can someone help me how to do that?

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    why don't configure the view where the data will be shown to be sorted by the date? you don't need to implement this logic inside a retrievemultiple plugin

  • Community Member Profile Picture
    on at

    We want to set the entity collection (this data is coming from fetch xml aggregate query) data to the virtual entity  . So for this we need to have entity collection before running this following code , we need to sort this Entity collection order by date descending.

    context.OutputParameters["BusinessEntityCollection"] = entityCollection;

    And with the help of view it is not possible.

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    the entityCollection in your line of code is probably defined as

    EntityCollection entityCollection = new EntityCollection();

    if you define your records like

    List entities = new List();

    you can do this line to add the entities like

    entityCollection.Entities.AddRange(entities);

    so you just need to sort (with LINQ) the List<Entity> with your criteria.

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Try below code

    var responseRoomAllocDetails=roomAllocDetails.Entities.OrderByDescending(x => x.Attributes["createdon"]).Select(x => x);

  • Community Member Profile Picture
    on at

    var responseRoomAllocDetails = entityCollection.Entities.OrderByDescending(x => x.Attributes["pp_lastlogindatetime"]).Select(x => x);

                   context.OutputParameters["BusinessEntityCollection"] = entityCollection;

    This code is not showing any error , but what i am trying to achieve is still not achievable for me

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    It is not working because you are passing original EntityConnlection object to output parameter

    You need to do as below

    var entityCollection = new EntityCollection<TEntity>();

    foreach (var item m in list)

    {

     entityCollection.Add(m);

    }

    Replace list with responseRoomAllocDetails

    Then pass entityCollection to output parameter

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans