Query where field is Enum value

Hello, I’m new to Fibery and lack programming skills but I’m setting up a scenario through Integromat that’s supposed to update a enum field based on various things outside of Fibery.

When doing it through Integromat you need to send the fiberyID for the enum, when hardcoding it it works fine but since the enum is 34 different options I need to send the FiberyID

Example:
image
equals
5d91fa30-77d5-11ec-873c-79fed3408808

So i figured I could do an API request to search for the specific enum ID and pass it to update later on, but running into issues when doing the query for enum value

This request works fine because FDFilial is just a text field.

[
{
“command”: “fibery.entity/query”,
“args”: {
“query”: {
“q/from”: “EBB-Database/DatabaseEBB”,
“q/select”: [
“fibery/id”,
{
“EBB-Database/Filial”: [
“fibery/id”,
“enum/name”
]
}
],
“q/where”: [
“=”,
[
“EBB-Database/IMEI”
],
“$search”
],
“q/limit”: 1
},
“params”: {
“$search”: “357010078609011”
}
}
}
]

But when trying to search for ‘Filial’ (which is a enum field) with the request

[
{
“command”: “fibery.entity/query”,
“args”: {
“query”: {
“q/from”: “EBB-Database/DatabaseEBB”,
“q/select”: [
“fibery/id”,
{
“EBB-Database/Filial”: [
“fibery/id”,
“enum/name”
]
}
],
“q/where”: [
“=”,
[
“EBB-Database/Filial”
],
“$search”
],
“q/limit”: 1
},
“params”: {
“$search”: “013”
}
}
}
]

I get

{
“success”: false,
“result”: {
“name”: “entity.error/query-func-expr-type-invalid”,
“message”: “Invalid query func expression database q/field-secured-access?, q/in, fibery/acl, fibery/access-group, fibery/id, $fibery/user-group-ids, EBB-Database/Filial, {“param-var”:”$anon-param17",“param-type”:“fibery/nil”}."

So what am I doing wrong?

Any help would be grateful
Thanks in advance

The enum field is actually a type of its own behind-the-scenes. So to get the id of an enum, you need to query the enum database.
The enum database name will be something like ${app}/${field}_${app}/${holder-type}
where field is the enum field name and holder-type is the name of the database.

By the way, you wrote

but perhaps you meant
“This request works fine because IMEI is just a text field.” ?

Yeah, you are correct, I had so many tabs up I mixed it up but the result is the same.

I guess I must have missed that enum type is it’s own database, I will try to make your solution work with.

${app}/${field}_${app}/${holder-type}

Thank you!

1 Like

Hm, not really getting this to work

I have a few enum fields and when trying this post

[
         {
           "command": "fibery.entity/query",
           "args": {
             "query": {
               "q/from": "EBB-Database/Filial_EBB-Database/DatabaseEBB",
               "q/select": [
                 "EBB-DataBase/Filial"
               ],
               "q/limit": 1
             }
           }
         }
       ]

I get

"message": "Invalid query.\nCause: EBB-Database/Filial_EBB-Database/DatabaseEBB database was not found."

So seems like it can’t find the database, but when trying another field

[
         {
           "command": "fibery.entity/query",
           "args": {
             "query": {
               "q/from": "EBB-Database/DeploymentStatus_EBB-Database/DatabaseEBB",
               "q/select": [
                 "EBB-DataBase/DeployementStatus"
               ],
               "q/limit": 1
             }
           }
         }
       ]

I get

"message": "Invalid query.\nCause: EBB-DataBase/DeployementStatus field was not found in EBB-Database/DeploymentStatus_EBB-Database/DatabaseEBB database."

I’m definitely doing something wrong but it seems it doesn’t find the database at all, but the second post it finds the database but not the correct field?
Even though both ‘Filial’ and ‘DeploymentStatus’ is in the same database.

It looks like the latter has a spelling mistake:

EBB-DataBase/DeployementStatus

unless I’m mistaken.
Not sure what might be the problem with the former.

Perhaps you could post a screen grab of all the fields in your database.
Alternatively. you can use the getSchema() api call to find the names of all the databases and fields etc.

The spelling mistake was indeed there but same result with correcting it.

I did a get schema call and for some reason it’s named Filial_New Space while other fields are not

{
                            "fibery/name": "EBB-Database/Filial",
                            "fibery/type": "EBB-Database/Filial_New Space/DatabaseEBB",
                            "fibery/deleted?": false,
                            "fibery/meta": {
                                "ui/object-editor-order": 0,
                                "fibery/type-component?": true,
                                "fibery/relation": "84e062c0-77d5-11ec-9234-4d6c82e7b87f",
                                "fibery/secured?": true,
                                "fibery/required?": false,
                                "ui/type-editor-order": 4,
                                "fibery/entity-of-field-type-can-be-created-by-creator-only?": true
                            }

I kind of confused myself now but unsure what I should put in the call to find enum IDs

[
  {
    "command": "fibery.entity/query",
    "args": {
      "query": {
        "q/from": "EBB-Database/Filial_New Space/DatabaseEBB",
        "q/select": [
          "fibery/id",
          { "EBB-Database/Filial_New Space": ["fibery/id","enum/name"] }
        ],
        "q/where": [
          "=",
          [
            "EBB-Database/Filial_New Space"
          ],
          "$search"
        ],
        "q/limit": 1
      },
      "params": {
        "$search": "013"
      }
    }
  }
]

I’ll get one of the devs to join this chat, since I’m not an API expert, but I think you might need to use the following

[
  {
    "command": "fibery.entity/query",
    "args": {
      "query": {
        "q/from": "EBB-Database/Filial_New Space/DatabaseEBB",
        "q/select": [
          "fibery/id",
          "enum/name"
        ],
        "q/where": [
          "=",
          [
            "enum/name"
          ],
          "$search"
        ],
        "q/limit": 1
      },
      "params": {
        "$search": "013"
      }
    }
  }
]

Cheers to adding someone in, and thank you for the patience .

I tried the call and got

[
    {
        "success": false,
        "result": {
            "name": "entity.error/query.invalid",
            "message": "Invalid query.\nCause: 'EBB-Database/Filial_New Space' field was not found in 'EBB-Database/Filial_New Space/DatabaseEBB' database.",
            "data": {
                "top": {
                    "error/name": "entity.error/query.invalid",
                    "errors": [
                        {
                            "error/name": "entity.error/schema-field-not-found",
                            "field": "EBB-Database/Filial_New Space",
                            "type": "EBB-Database/Filial_New Space/DatabaseEBB"
                        }
                    ]

Sorry, I made a mistake, but have now edited my previous response. Can you try again.

Oh wow, cheers.

Really, thanks a lot for the time and the help!

So I assume that means you got it working… :+1:

Yeah indeed, I marked it as the solution if anyone else is having issues.

Thanks again.