Sort order items of an itemtype by date (created_on property)

オフライン

Hello,

Is there any way in the configuration to retreive all items of an ItemType sorted by date (created_on property) when runing search.

otherwise i have developped a server method without success: 

Innovator inn = this.getInnovator();

Item Items = inn.newItem("name of the ItemType","get");


Items.setAttribute("orderBy", "[name of the ItemType].created_on desc ");

return Items.apply();


Any help please ?

  • Hi 

    small change in your code will do the trick.

    Innovator inn = this.getInnovator();
    Item Items = inn.newItem("Part","get");
    Items.setAttribute("orderBy", "item_number DESC");
    return Items.apply();

    Thank You

    Gopikrishnan R

  • オフライン in reply to Gopikrishnan

    Hi,
    Thanks for your reply.

    Can you tell me please which event should i applied to the method as i have tried with onBeforeUpdate, onBeforeAdd, onGet, onBeforeget, onAfterGet without success.

  • Hello,

    You can configure this directly from the ItemType without needing to write any code by following the steps below.

    1. Login as admin
    2. Navigate to the desired ItemType
    3. Click the Edit button
    4. Go to the Properties relationship tab
    5. Scroll down to created_on and enter '1' in the Order By column
    6. Check the other properties to ensure there is no other Order By set
      1. If there is, either remove it or make sure it is a number greater than '1'
    7. Save and close your ItemType

    When the results of a query are returned for an ItemType, it checks to see if any properties have an Order By set. If there is just one property, the results of the query are sorted by that property. If there is more than one property, the results are first sorted by the property with the lowest value and then by the property with the next lowest value and so on.


    Chris

    Christopher Gillis

    Aras Labs Software Engineer

  • Hello Chris,

    Thank you for your reply,

    This is what i have done, the results of the query are sorted by that property (created_on) but in ascending order and not

    descending.

    Do you have an idea on how to get the results in DESC order ?

  • Hi mouad,

    Thank you for clarifying. Your assumption was correct originally then, it is not currently possible to configure whether the sort should happen in ascending or descending order purely through the ItemType.

    You can do this programmatically through an onBeforeGet event though. The code is pretty simple and can be seen below.

    this.setAttribute("orderBy","created_on desc");
    return this;

    There's no need to even do an apply since that will happen automatically as part of the standard Get functionality of Aras Innovator.

    Chris

  • Thanks Chris, this is very Helpful

  • Thanks for this info.  It worked for me as well.

  • オフライン in reply to Christopher Gillis

    Hi Cris,
    this approach is extremly critical!
    The problem is that all AML querys in the methods with a different sortOrder return a wrong result.
    Because the OnAfterGet is overruling the sort order in the AML query.

    Any other approach to sort descending in the searchgrid?

  • Chris is not longer at Aras. But he will always be remembered as the official saint of this forum!

    The solution is perfect, when using a "onBeforeGet" Method! This way the AML result is sorted before being displayed in the grid.

  • オフライン in reply to AngelaIp

    This is working well in the searchgrid.
    But we had a lot of issues after setting the sort order in the OnBeforeGet server event and many actions and programs where not working properly after that.

    example:
    Method in the Part ItemType OnBeforeGet
    Set the item_number sort order to descending

    this.setAttribute("orderBy","item_number desc");
    return this;

    Run an AML with a different sort order:
    In this example want the item_number sorted not descending but ascending
    <Item type="Part"  action="get" select="item_number,name" orderBy="item_number asc">
      <name>Extruderhalter</name>
    </Item>

    Result: sort order is descending!
    The OnBeforeGet event has overruled the sort order!

    This is extremely critical because there are a lot of (custom) AML querys with different sortOrder in the methods code and the result is unexpected!
    To get the expected result a serverEvents="0" Attribute is neccessary in the AML query.
    But that would mean that all methods with AML queries and sortOrder have to be investigated and changed.