Sorting Link Field Results by Last Modified (Latest First)

Hi everyone,

I’m working with a Link field where users select Purchase Orders.

I’d like the dropdown results to be sorted by “Last Modified” (latest first) so that recently updated Purchase Orders appear at the top.

I’m able to apply filters successfully, but I haven’t found a way to control the sorting order of the results.

Is there any standard or built-in way in Frappe to define sorting for Link field results (for example, by modified desc) without using custom scripts like set_query?

I’m looking for a simple or configuration-based approach, if one exists.

Thanks in advance!

Hi,

The cleanest supported approach is to use frm.set_query (or a custom server‑side query) and add an ORDER BY modified DESC clause there. If you really want to avoid scripts, you’ll have to accept the default sort order for the Link‑field dropdown.

FYI, this has already been requested as a feature in Frappe: Add feature to set Sort field in Link Field · Issue #32252 · frappe/frappe · GitHub.