Gosforth
Gosforth

Reputation: 51

How to get Data Object field value in task?

I have a data object ProcessDataObject. This object has fields amount, department.

Process form base on this data object (so in form I have fields amount, departement).

In process data, I have process variables:

enter image description here

How to get departement field value I put in form starting the process?

In user task in 'Data Inputs and Assignments' I tried everything like 'ProcessDataObject.departement':

enter image description here

But it does not work - I cannot get 'departement' name in the task or other project object.

Upvotes: 0

Views: 45

Answers (2)

Gosforth
Gosforth

Reputation: 51

I decided to recreate project this time with different data object name. I suspect that the name data object could be treated as a reserved variable name. And this time, with a unique name for the data object... it worked. I took the 'department' variable from the data object using JavaScript (On Entry Action) - in Task. I wanted to regenerate the problem again but despite deleting that data object when starting a new process there is an error... this old data object is somewhere in memory/on disk. I give up. So 99% sure something was wrong with the name 'ProcessDataObject'.

JBPM is a very rickety system full of bugs and errors.

Upvotes: 0

jomarko
jomarko

Reputation: 267

I think your use case can be achieved using kcontext.getVariable() construct. You can see it in action in existing codebase [1].

So it is a java code you can put into a Task definition - On Exit Action. Then, this code will be executed once the task is completed. As the code can access a process variable, you should be able to access ProcessDataObject.department and eventually store it into a new variable using kcontext.setVariable.

[1] https://github.com/search?q=repo%3Aapache%2Fincubator-kie-kogito-runtimes+kcontext.getvariable+language%3AXML&type=code

Upvotes: 0

Related Questions