Take the community feedback survey now.

Customized Commerce Order Search API for PurchaseOrder with OrderByClause

Vote:
 
Using EPiServer.Commerce 13.19.0
 
I'm having an issue with using the Order Search API for PurchaseOrders doesn't allow the OrderByClause to reference META columns (on the OrderGroup_PurchaseOrder table).
 
 
However, even if I use an out of the box column like Created, it throws an exception:
 
It has no such errors when trying with OrderByClause = "OrderGroupId DESC" or OrderByClause = "CustomerName DESC"
 
Does anyone know if this is a bug or if there's anything I can do to make it work?
#340322
Sep 10, 2025 2:59
Vote:
 

Hi Matthew

The Created column is in the PurchaseOrder table. You can filter by it using the SqlMetaWhereClause.

But there is no such ordering clause for that table.

However, as I recall, the result is ordered by the object ID, which is sequential and can be used as a stand-in for the Created date (if you need ascending order).

OrderByClause works with CustomerName, because that field is in the OrderGroup table.

#340323
Sep 10, 2025 4:30
Vote:
 

Hi Stefan,

Thanks for the response, but I'm specifically interested in the documented OrderByClause as I need to control the sorting of the results (within pagination).

I have realised (and is documented) that it orders by the OrderGroup.OrderGroupId DESC which makes sense for many use cases. But I actually need to sort by another column that has been added to the OrderGroup_PurchaseOrder. My example of using the META.Created DESC is just to test if even an out of the box column would work - and also be common to discuss with other devs since it's known. Ultimately I need it to use another column anyway which is not going to be consistent with the OrderGroup.OrderGroupId, unfortunately.

So I don't think SqlMetaWhereClause or the default order helps in my use case.

Ideally, I'm just wanting to use the OrderByClause as documented and as I've explained using the META column ordering.

Is there any reason you say "there is no such ordering clause for that table"? Or is it just that you've also discovered it doesn't work as designed, like I have now?

Matt

#340324
Sep 10, 2025 4:39
Vote:
 

Update: I have just updated all packages so I'm running EPiServer.Commerce v13.37.2 and the same issue remains. From digging around, it seems clear this issue is specifically with the stored procedure "ecf_Search_PurchaseOrder" (and it's subsequent called stored procedures). This definitely seems like it should work, and this appears to be some sort of bug - especially when considering the documentation. Here's an example error down at the SQL execution level:

#340326
Sep 10, 2025 5:00
Vote:
 

Hi, the documentation is wrong and inconsistent. It stated that "

  • OrderByClause – This clause can use only OrderGroup table fields. If this field is not set, OrderGroupId is used.

which is correct. I will file a bug to correct a documentation. Thank you for brining this into our attention and apologies for the inconvenience. 

#340352
Sep 11, 2025 8:06
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.