web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,084 Moderator on at
    RE: How to sort the entity collection order by descending of created on date in plugin.

    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
    RE: How to sort the entity collection order by descending of created on date in plugin.

    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,084 Moderator on at
    RE: How to sort the entity collection order by descending of created on date in plugin.

    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
    RE: How to sort the entity collection order by descending of created on date in plugin.

    Hi,

    Try below code

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

  • Community Member Profile Picture
    on at
    RE: How to sort the entity collection order by descending of created on date in plugin.

    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
    RE: How to sort the entity collection order by descending of created on date in plugin.

    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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 186

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 130 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans