Using dataObject in ScriptTaskListener

Hello to all,

I am trying to create dataObject that will create some script to be executed on user task. The idea behind is to avoid duplication of code, because I will have several user Tasks that will need to execute the same script, setting the same task local variables.
According to documentation data objects are converted to process variables, and I though that I could use the content of the process variable as script to be executed.
In xml definition I have

        <dataObject itemSubjectRef="xsd:string" id="dataObjectTest" name="dataObjectTest">
                    task.setVariableLocal("variable1", "value1");
                    task.setVariableLocal("variable2", "value2);]]>

In user task

        <userTask id="myTaskId" name="My task">
                <flowable:taskListener event="create"
                    <flowable:field name="script">
                    <flowable:field name="language" stringValue="JavaScript"/>

I tried almost all combinations for setting script with expression or string elements and I always get the exception

nested exception is org.flowable.common.engine.api.FlowableException: Exception while invoking TaskListener: Exception while invoking TaskListener: problem evaluating script: <eval>:1:1 Expected ; but found {
 ^ in <eval> at line number 1 at column number 1] with root cause

jdk.nashorn.internal.runtime.ParserException: <eval>:1:1 Expected ; but found {

I don’t know it this is good idea at all or maybe I should look for some other solution but I was following the example:

Thank you!

Hi Ficus.

The question is: “How to access process variables in the ScriptTaskListener?”

		<userTask id="usertask1" name="All your base are belong to us">
				<activiti:taskListener event="create" class="org.flowable.engine.impl.bpmn.listener.ScriptTaskListener">
					<activiti:field name="script">
            	task.setVariable('foo', task.getProcessVariables().get('var')); // pushes variable to execution context
					<activiti:field name="language" stringValue="groovy" />

Check whether process variables are set on the task.


Hi Martin,

Thank you for answering.
Process variable is already set, I checked the db. My problem is that I want to use content of process variable to be executed as script. The reason why I am doing this is to create smaller xml, I am implementing decision tree with flowable and some nodes are similar, I have userTasks where I set completely the same local variables. Maybe I should try with common delegate if this is not possible…

Best regards


ScriptTaskListener does not support “script expression”. If you want to get a support for that, add ExpressionManager evaluation to ScriptTaskListener class.
Currently there is only support for the plain text:

Object result = scriptingEngines.evaluate(script.getExpressionText(), language.getExpressionText(), delegateTask, autoStoreVariables);