Query on workflow state

Hello Fibery Community,

I’m encountering an issue when trying to query entities based on their workflow state using the Fibery API. I’ve set up a workflow with several states for my “Buchhaltung/Beleg” entity type, including a state named “Freigegeben zum Datentransfer”.

When I try to query for entities with this workflow state using the following API call:

{
  "command": "fibery.entity/query",
  "args": {
    "query": {
      "q/from": "Buchhaltung/Beleg",
      "q/where": ["=", ["workflow/state", "enum/name"], "Freigegeben zum Datentransfer"],
      "q/limit": 10,
      "q/select": [
        "fibery/id", 
        "Buchhaltung/Dateiname",
        // other fields...
        "workflow/state"
      ]
    }
  }
}

I receive the following error:

{
  "success": false,
  "result": {
    "name": "entity.error/schema-field-not-found",
    "message": "\"Freigegeben zum Datentransfer\" field was not found in \"Buchhaltung/Beleg\" database.",
    "data": [Object]
  }
}

What’s confusing is that I can verify this workflow state exists in my Fibery database. When I query for all workflow states, I get:

[
  {
    "fibery/id": "6788bc80-147c-11f0-a690-9d116968b0ba",
    "enum/name": "Neuer Beleg"
  },
  {
    "fibery/id": "6788bc81-147c-11f0-a690-9d116968b0ba",
    "enum/name": "Freigegeben zum Datentransfer"
  },
  // other states...
]

What is the correct way to query entities by their workflow state name using the Fibery API? Am I missing something in my query structure?

Thank you for your help!

You need to use params to pass the name of the option you want to use in your query, otherwise, it thinks that the string you are passing is the name of a field.

Try

"q/where": ["=", ["workflow/state", "enum/name"], "$option"]

and then add a params section to your query:

"params": {
    "$option": "Freigegeben zum Datentransfer"
}

The user guide actually has an example of this:

(look for Get right-handed players — single-select)

1 Like

Thank you very much! This is the solution!