Python External Task Complete & Tasklist

Hi,
I’m trying to modify the example project of the get started guideline from camunda.

I use Python for the external task client (GitHub - yogeshrnaik/camunda-external-task-client-python3: Camunda External Task Client in Python).
Scripts ends with:
return task.complete({“item”: item, “amount”: amount})

The process works and ends succesfully if the amount is below 1000.
But if the amount is higher than 1000 I want an additional human task.

I get the following error in tasklist & these are my settings for Check Payment:

What did I wrong?

Thanks for help!

One this is that you don’t need to add the default value.
By default if the variable specified already has a value, it will be populated by the form, so you can remove the expression you have.

The details of the error you experience are likely going to be in logs,i would check that out to see about what specifically is wrong.

1 Like

Hi Niall,
thanks, I removed the default values.

I found the following in the logs:
Caused by: java.lang.NumberFormatException: For input string: “2116.190476190476”
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68) ~[na:na]
at java.base/java.lang.Long.parseLong(Long.java:707) ~[na:na]
at java.base/java.lang.Long.(Long.java:1344) ~[na:na]

So the variable “amount” has a wrong datatype or what does it mean?

The form is expecting a Long but you’re sending a String from your worker.
So either change the form so that it displays a string or change the worker to return a Long

I made this change & now it it works:

I wanted to know whether the variable “amount” will then be classified as integer / long in the further process or as a string. For this reason I added a gateway. Seems to work anyway and the data type is Integer / Double at the end of the process. I just wondered why that is.

But process is working, thank you!

Another question:
How would the query / code via REST-API look like if I post the two variables directly into the human task (“Check Payment”). I know how to start a process right from the start via REST, but is it also possible to start the process in the middle and skip previous steps? If not, is there still a chance to implement variables in an existing process?

I didn’t find anything suitable in the documentation. For example, I tried the following:

url = ‘http://localhost:8080/engine-rest/process-definition/key/ed069466-9237-11eb-a3d3-1cbfc00f9269/start

myobj = {“workerId”: “1”,
“variables”: {“amount”: {“value”: 11.111, “type”: “double”},
“item”: {“value”: “test”, “type”: “string”}}
}

x = requests.post (url, json = myobj)

So the process instance ID in the URL which I started with:
url = ‘http://localhost:8080/engine-rest/process-definition/key/payment-retrieval/start

myobj = {
“variables”: {“amount”: {“value”:11.111,“type”:“double”},
“item”: {“value”:“test”, “type”:“string”} }
}

x = requests.post(url, json = myobj)

Hey @svenr,

If you want to start the process at a different point, you have to adjust your process model by adding another message start event. [forum.bpmn (6.5 KB) ] This can be then triggered via REST-call and you can pass the variables within the call.

If the process is started and the instance is at the user task, you can also claim the task and complete it via REST API and pass variables along. You could also add a form field that will declare a variable and the user in the user task can then initials the value.

Another way of achieving this in the process logic could be to model an event subprocess with an non-interrupting message start event. The message that is sent can contain variables (same call as the start message). But be aware of message correlation.

If your model does not contain the possibility to pass variables at defined points, you can add and change Variables inside Cockpit, but this would be more the approach for an administrator to fix something.

Regrading the variable problem, that seems a little bit odd. How does the JSON look like that you send with the complete call. If you have the numeric value in quotation marks, that could lead to the problem that the engine first recognize it as a String.

I hope that helps. Kind regards
Nele

2 Likes