Skip to main content

Notifications

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

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

Posted on by Microsoft Employee

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?

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 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

  • Community Member Profile Picture
    Community Member Microsoft Employee 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
    Bipin D365 28,964 Super User 2024 Season 1 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);

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 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.

  • Community Member Profile Picture
    Community Member Microsoft Employee 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
    Guido Preite 54,081 Super User 2024 Season 1 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

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans