CodamAIDocs
Topicdone

Sorting

Several sort criteria, direction ASC/DESC/NONE, sorting across relations, and what happens with a wrong sort path.

Variants
ASCDESCNONEseveral criteriavia pathwithout ordercriterion without directionwrong path → 400

What this is about

order in parameter sets the order of the matches. It is a list of criteria:

"order": [
  { "field": "active", "order": "ASC" },
  { "field": "amount", "order": "DESC" }
]
KeyMeaning
fieldthe field, also as a path like company.companyname
orderASC ascending (A → Z, 1 → 9, old → new), DESC descending, NONE do not sort

Sorting in stages

Example data and order as above:

labelactiveamount
Alphatrue5
Betafalse10
Gammatrue15
flowchart LR
    A["Stage 1: active ASC<br/>false before true"] --> B["Beta (false)"]
    A --> C["Alpha, Gamma (true)"]
    C --> D["Stage 2: amount DESC<br/>on a tie"]
    D --> E["Gamma (15), Alpha (5)"]

Result: Beta, Gamma, Alpha.

All variants

Sorting in all forms

When: one column, one direction

[{ "field": "amount", "order": "DESC" }] returns Gamma, Beta, Alpha.

Result: Sorted by one field.

When: Ties should be resolved in a stable way.

Add more criteria. A unique field like id or _createdOn works well as the last criterion. Then the order is always the same.

Result: An order without randomness.

When: A user interface turns off sorting for a column but still sends the criterion.

{ "field": "amount", "order": "NONE" } is skipped.

Result: As if the criterion were not there.

When: { "field": "amount" } or { "order": "ASC" }

An incomplete criterion is skipped, without an error.

Result: As if the criterion were not there.

When: Sorting by a field of a referenced object: { "field": "company.companyname", "order": "ASC" }.

Only objects that have this relation appear. Employees without a company are missing from data, but totalCount counts them. See Filtering and sorting across relations.

Result: Sorted by the company name.

When: order is missing or empty.

The database returns the matches in an order it picks itself. This order can change between two calls.

Result: Not defined. When paging, objects can appear twice or be missing.

When: { "field": "nope", "order": "ASC" } or { "field": "company.nope", "order": "ASC" }

  1. 1
    CDMS
    looks for the field in the model
  2. 2
    CDMS→Client
    not found → 400 wrong-order-element-exception

Result: 400. Unlike a wrong filter, a wrong sort field is not silently ignored.

Decision table

What happens to a sort criterion?
fieldorderResult
presentASC / DESCis applied
presentNONEskipped
missing–skipped
–missingskipped
unknownASC / DESC400 wrong-order-element-exception
–lower case, e.g. asc400 invalid-value|parameter.order[0].order

Traps

Sources in the code and the knowledge base
  • CDMS/cdms-persistence-database – DatabaseOrderBuilder
  • CDMS/cdms-commons – ListOrderLogic, SearchSortOrder
  • Probe against cdms-integrationtest (preset, employee), 2026-09-21
Search