Forum Discussion
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.
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.
- angela2 years agoCatalyst II
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
- roval2 years agoIdeator II
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- Anonymous2 years agoNot applicable
Thanks Chris, this is very Helpful