Sort Historic Processes/Tasks By Process Variable

I am using the Rest API POST /history/process-instance endpoint to get all process instances and I would like to sort the response by the value of a process variable.

Example:
I have process instances with the process variable lastName. I would like to sort my process instances by lastName so that I can show all process instances in a sorted dashboard.

I would also like to sort the POST /history/task endpoint response by process variable.

This behavior seems to be supported in the POST /task endpoint (but not the POST /process-instance endpoint) by:

"sorting":
    [{"sortBy": "processVariable",
    "sortOrder": "desc",
    "parameters": {
      "variable": "lastName",
      "type": "String"
    }}]

Based on the API documentation (Get Process Instances (POST) | docs.camunda.org and Get Task (Historic) (POST) | docs.camunda.org), sorting by process variables is not supported in the same way.

Is there any way to sort the responses from the /history/task or /history/process-instance endpoints by process variable? Has anyone else come across this issue?

You may not like this answer, but you can go directly to the database (READ-ONLY) and get what you’re looking for. Then you’re only restricted by the SQL you can write.

So in your case it might be:

SELECT PROC_INST_ID_, NAME_, TEXT_ FROM ACT_HI_VARINST WHERE NAME_ = 'lastName';

Thanks @mppfor_manu! I’ll take your advice and directly query the database.

@mppfor_manu

Is there any REST API that gives the same result?

@Hilary_Mulholland

Did you find any solution to this. I am having a similiar issue.

Thanks in advance.

You might be able to do this through the history/process-instance method. See the documentation below (you should select the version appropriate to your installation).

https://docs.camunda.org/manual/7.6/reference/rest/history/process-instance/get-process-instance-query/

Hey,

Is there a REST API solution to do this? Or it is still not possible to sort processes by process variables?

1 Like