ScriptTaskListener and passing assignee from task to execution

I am new in Flowable and I want to pass assignee from user task.
I have created ScriptTaskListener (org.flowable.engine.impl.bpmn.listener.ScriptTaskListener) on user task on event complete.
script: execution.setVariable(“approvedBy”, task.getVariable(“assignee”));
Execution context is not available in this case. :frowning:

there is:
foo = “FOO”; // pushes variable to execution context
not working (variable not exist after that)

def bar = “BAR”; // local variable
not working - log has said
Caused by: javax.script.ScriptException: :1:4 Expected ; but found approvedBy
def approvedBy = task.getVariable(“assignee”);
How to pass assignee from task to execution?

A task is a scope for variables too. So if you do task.setVariable(“newAssignee”, “foo”), that should work.

I have found a solution.
All is in documentation.
ScriptTaskListener must be language=groovy and resultVariable must be set (approvedBy).
approvedBy = task.getAssignee();

While the solution presented here using a ScriptTaskEventListener works, have there been any other ways to access task scoped variables introduced since this solution was presented? I’m thinking of something similar to how form outcome variables can be referenced in gateways? Something along the lines of {task_mytaskid_assignee} like {form_myform_outcome}.

Could something similar be done using a script task after the human task or does it have to be within the human task because that information is not maintained within the runtime after the human task completes?


After thinking this through a bit more I think the original suggested approach likely makes more sense as it keeps the downstream task from being dependent on the existence or execution of an earlier task which, depending on the process design, may or may not occur.

That being said, having to set the variable via the ScriptTaskEventListener felt a bit cumbersome so I did find that your suggestion of using task.setVariable in the TaskEventListener was a more direct approach.