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 ?

  • Ah ok! Now I understand your problem and I confirm this behavior. Indeed, the custom AML can be overruled.

    Maybe you can check in your Method if certain attributes are present that are typically used for the search grid. Typically the "page" attribute, but there are also others like pagesize or return mode:


    string page = this.getAttribute("page","");
    if (page == "")
    {
       return this;
    }

    this.setAttribute("orderBy","...");

    Edit: Maybe an even better variant! Check if an orderBy attribute is passed already and skip the Method if this is the case.

    string orderBy = this.getAttribute("orderBy","");
    if (orderBy != "")
    {
       return this;
    }

    this.setAttribute("orderBy","...");

    I haven´t tested any of this variants, but I like the second idea very much! Please let me know if any of them work! I think I will implemented them too.

    Best regards!

    Angela

  • Hi Angela,
    the second idea looks good.
    I tested this and it works perfectly now.

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


    Thank you for this great approach,
    Ronald

  • Thanks Chris, this is very Helpful