How to filter a variable instance of 'Object' type based on its attributes

I have a variable for my process instance as below:

“customerDetails”: {
“type”: “Object”,
“value”: {
“accountNumber”: “5566778899112233”,
“customerName”: “John Flencher”,
“custId”: “112233808”,
“customerEmailAddress”: “John@gmail.com
},
“valueInfo”: {
“objectTypeName”: “java.util.LinkedHashMap”,
“serializationDataFormat”: “application/x-java-serialized-object”
}
},

Is there any way i can filter variable instances based on the attributes of the object. For example, i want to search something like this: customerDetails.custId=123

Hi @startrek,

you can’t filter Object variables, as they are stored in a LOB column in the database.

But you can extract the attribute you want to filter into an additional variable of type string.

Hope this helps, Ingo

Hi @Ingo_Richtsmeier, Thanks for your reply ! If you could describe this with an example it would be immensely helpful

Hi @startrek,

this may work:

  public class ExampleExecutionListenerOne implements ExecutionListener {

    public void notify(DelegateExecution execution) throws Exception {
      LinkedHashMap customerDetails = (LinkedHashMap) execution.getVariable("customerDetails");
      execution.setVariable("customerId", customerDetails.get("custId"));
    }
  }

You can get further details here: https://docs.camunda.org/manual/7.11/user-guide/process-engine/delegation-code/#execution-listener

Hope this helps, Ingo

@Ingo_Richtsmeier My original requirement is to fetch process instances based on the search filters using camunda rest APIs. For example, i would like to filter process instances based on its variables. In my case, I want to find out process instances that are created for a particular customer i.e customerDetails.custId=12345 or any other such parameter of a customer object. Is it possible ?

AFAIK you can only filter process instances by top level variables; preferrably strings, but other atomic types (e.g. integer) might works as well – you’ll have to check.

Hi @startrek

As Ingo mentioned that you can’t filter Object variables, as they are stored in a LOB column in the database.

In your case, what you can do is:

  1. Store customerDetails.custId in another process variable say “customerId”. The sample code would look like as follows.

    LinkedHashMap customerDetails = (LinkedHashMap) execution.getVariable(“customerDetails”);
    execution.setVariable(“customerId”, customerDetails.get(“custId”));

    // if you want to do search based on another attribute of customer say “accountNumber”
    execution.setVariable(“accountNumber”, customerDetails.get(“accountNumber”));

  2. Now, you can fetch process instances based on “customerId” variable. For example:

http://localhost:8080/engine-rest/process-instance?variables=customerId_eq_12345

or

http://localhost:8080/engine-rest/process-instance?variables=accountNumber_eq_110001

Please note that you need to provide variable name and value in the format “customerId_eq_12345”. Here “eq” is for “equals”.

If you want to filter process instances based on multiple customerDetails attribute, then you would have to create that many process variables in the same way as described in point 1.

Here is the link of the process instance rest api that can filter based on variables: https://docs.camunda.org/manual/latest/reference/rest/process-instance/get-query/#example

Best,
Garima

Hi @garima Thanks for your time and effort :slight_smile: This solution seems to be feasible for the aforementioned problem. I am definitely going to try this. :slight_smile:

@garima And also, do you have an idea on how we can enforce the engine to validate the request parameters when the camunda rest api is invoked? For example, i would like to update the variables using the camunda rest api with a check on the input data. Is this possible?