Fetch and Lock external variable by processVariables

Hi all,

I’m trying to fetch and lock an external task but instead filter by businessKey, filter by processVariables but I’m getting an empty list.

This is my json with businessKey who fetch correctly the task:

{
"workerId": "offerWorkerId",
"maxTasks": 1,
"topics": [
    {
        "topicName": "offerCalculationTask",
        "lockDuration": 1000,
        "variables": [
            "energyType",
            "offerId"
        ],
        "businessKey": "1001"
    }
]
}

But using this request i’m getting an empty list:

{
"workerId": "offerWorkerId2",
"maxTasks": 1,
"topics": [
    {
        "topicName": "offerCalculationTask",
        "lockDuration": 1000,
        "variables": [
            "energyType",
            "offerId"
        ],
        "processVariables": {
            "name": "offerId",
            "value": 1001
        }
    }
]

}

So, question is, how can I filter by processVariables to get a specific external task?

Thank you so much!

I am using Camunda 7.11 and i am facing exactly the same problem.

Anyone found a solution or is this a bug?

In my case, finally I’m using a filter by BusinessKey, since I can’t filter by processVariables :frowning:

Hi,

sorry for the late response. Looking at your example, I guess you need to write it like this:

{
"workerId": "offerWorkerId2",
"maxTasks": 1,
"topics": [
    {
        "topicName": "offerCalculationTask",
        "lockDuration": 1000,
        "variables": [
            "energyType",
            "offerId"
        ],
        "processVariables": {
            "offerId": 1001
        }
    }
  ]
}

The processVariables have to be used as a key-value-object where the key resembles the process variable name and the value resembles the process variable value to filter by.

Hope that helps you in using it to your needs!

Best,
Tobias

1 Like

Don’t worry!
Thanks about response, but I’m afraid it doesn’t work using as key-value :frowning:
Anyway, as I said, I’m using the businessKey as filter.

Thanks!

Hi @pipeline,

I’m glad the solution with the business key works for you!

However, others might look at this thread and try to find a solution.
The crucial part for the processVariables is that you use it correctly.
I just want to emphasize that your example

        "processVariables": {
            "name": "offerId",
            "value": 1001
        }

should actually work fine if you write it like

        "processVariables": {
            "offerId": 1001
        }

Did you try to use it that way?
Any feedback on this suggestion might help others looking for answer here as well.

Best,
Tobias

1 Like

Hi @tmetzke,
Of course, you are right, and other could look for a correct solution.
I create a new process just with one external task, so simple:

I started a new task from Tasklist with an offerId variable with 999 value, as you see on this screenshot. Then, I made a request via api to get all the external task:

GET: http://localhost:8010/engine-rest/external-task
Response:

[{
        "activityId": "Task_1hn8479",
        "activityInstanceId": "Task_1hn8479:c9fab06c-935a-11e9-bbfb-2a92c985093c",
        "errorMessage": null,
        "errorDetails": null,
        "executionId": "c9fab06b-935a-11e9-bbfb-2a92c985093c",
        "id": "c9fb73bd-935a-11e9-bbfb-2a92c985093c",
        "lockExpirationTime": null,
        "processDefinitionId": "Process_1:1:bc9a4fc5-935a-11e9-bbfb-2a92c985093c",
        "processDefinitionKey": "Process_1",
        "processInstanceId": "c9f50b16-935a-11e9-bbfb-2a92c985093c",
        "retries": null,
        "suspended": false,
        "workerId": null,
        "topicName": "myExternalTask",
        "tenantId": null,
        "priority": 0,
        "businessKey": "1234"
    }]

And now try to fetchAndLock this task:
POST: http://localhost:8010/engine-rest/fetchAndLock

{
    "topics": [
        {
            "topicName": "myExternalTask",
            "lockDuration": 30000,
            "variables": [
                "offerId"
            ],
            "processVariables": {
                "offerId": 999
            }
        }
    ],
    "workerId": "offerWorkerId",
    "maxTasks": 1
}

And the response is 200 with empty body, just []

But, I tried with an string and integer variable and it works:

POST: http://localhost:8010/engine-rest/fetchAndLock

{
    "topics": [
        {
            "topicName": "myExternalTask",
            "lockDuration": 30000,
            "variables": [
                "offerId",
                "variable1"
            ],
            "processVariables": {
                "variable1": "option1"
            }
        }
    ],
    "workerId": "offerWorkerId",
    "maxTasks": 1
}

Response:

[
    {
        "activityId": "Task_1hn8479",
        "activityInstanceId": "Task_1hn8479:c9fab06c-935a-11e9-bbfb-2a92c985093c",
        "errorMessage": null,
        "errorDetails": null,
        "executionId": "c9fab06b-935a-11e9-bbfb-2a92c985093c",
        "id": "c9fb73bd-935a-11e9-bbfb-2a92c985093c",
        "lockExpirationTime": "2019-06-20T15:09:41.564+0200",
        "processDefinitionId": "Process_1:1:bc9a4fc5-935a-11e9-bbfb-2a92c985093c",
        "processDefinitionKey": "Process_1",
        "processInstanceId": "c9f50b16-935a-11e9-bbfb-2a92c985093c",
        "retries": null,
        "suspended": false,
        "workerId": "offerWorkerId",
        "topicName": "myExternalTask",
        "tenantId": null,
        "variables": {
            "variable1": {
                "type": "String",
                "value": "option1",
                "valueInfo": {}
            },
            "offerId": {
                "type": "Long",
                "value": 999,
                "valueInfo": {}
            }
        },
        "priority": 0,
        "businessKey": "1234"
    }
]

Regards!

PD: I forgot mention, I’m using Camunda 7.10

Hi @pipeline,

great to see that it at least works with a String variable for you as well! :slight_smile:
Thanks for taking the example and trying it out!

I will investigate on the other variable types again and see if I can determine why the Long value variable didn’t work for you.

Could you tell me what tool you used to make the REST API requests?

Best,
Tobias

Of course!, It’s Postman application.

Thanks for your help :slight_smile:

@tmetzke Is there any update on this? Still doesn’t work with long type.

Hi @nikolam,

I can reproduce this with a Long type value in general. It works fine with an Integer type value, by the way. Plus, it also works fine with a Long type variable if the POST request uses a number value that can only be converted to a Long value because it’s too large for an Integer. Something goes wrong along the way when the variable is a Long and the request comes along with an Integer.

Edit: The REST API transforms the given value into the smallest possible Java data type. Therefore, a number value like 300 is transformed into an Integer. Thus, the query against our database to fetch the external task uses an Integer for filtering by the process variable. However, there is no variable with the given name of type Integer. As a result, no external task is found. This is tracked in CAM-14685.

Best,
Tobias

1 Like