Sub process cannot resolve variable passed by 'callAtivity'

cancel
Showing results for 
Search instead for 
Did you mean: 
Member II

Sub process cannot resolve variable passed by 'callAtivity'

I'm using `activiti-spring-boot-starter:7.1.0.M6`.

As I read [document][1], to pass process varibles to sub-process, I need to use

<!-- Main Process -->
<bpmn:callActivity id="mainActivity" name="TASK_NAME" calledElement="subProcess">
<bpmn:extensionElements>
<activiti:in target="subVarName" source="mainVarName"/>
<activitiSmiley Surprisedut target="mainVarName2" source="subVarName2"/>
</bpmn:extensionElements>
<bpmn:incoming>flow1</bpmn:incoming>
<bpmnSmiley Surprisedutgoing>flow2</bpmnSmiley Surprisedutgoing>
</bpmn:callActivity>

After I passed the variable, I thought it would be OK that process call `subVarName` in bpmn, but it wasn't.

I got `UnknownPropertyException` when engine referred `subVareName`.

<!-- Sub Process -->
<bpmn:serviceTask id="subActivity" name="SUB_TASK_NAME"
activiti:expression="${mySpringService.method(subVarName, execution)}">
<bpmn:incoming>subFlow1</bpmn:incoming>
<bpmnSmiley Surprisedutgoing>subFlow2</bpmnSmiley Surprisedutgoing>
</bpmn:serviceTask>

I already checked that `mainVarName` is not null because it is used by prior service task in main process.

Please let me know what I missed... Thanks!

[1]: https://www.activiti.org/userguide/#bpmnCallActivityPassVariables

4 Replies
Senior Member

Re: Sub process cannot resolve variable passed by 'callAtivity'

The guide you are referring to belongs to an older version. i don't see similar topic in Activiti7. can you please post this on the gitter channel?

Regards,
Abbas
Member II

Re: Sub process cannot resolve variable passed by 'callAtivity'

I solved problem by using 'taskListener'.

And what I missed is that subprocess from 'callActivity' cannot receive variables. I saw that kind of description in this community.

 

By the way, is there any difference of 'DelegationExecution' between 'taskListener' and 'ExecutionListener'?

 

When I completed task with task parameters, the former can retrieve variables but it disappeared, the latter does contrary.

 

Senior Member

Re: Sub process cannot resolve variable passed by 'callAtivity'

I believe task listener uses DelegateTask whereas execution listener uses DelegateExecution, so the tasklistener might have access to locally scoped task variables. could you please share some sample code for better clarity on behavior?

Regards,
Abbas
Member II

Re: Sub process cannot resolve variable passed by 'callAtivity'

Sorry, I solved problem by setting variable scope.

But for giving information about this, I'll append sample code.

When I completed task like below, 

taskService.complete(task.getId(), taskParam);

In my BPMN,

<bpmn:userTask id="myTask" name="My Task" activiti:assignee="assigneeProperty">
    <bpmn:extensionElements>
        <activiti:taskListener
                expression="${mySpringService.methodToTrigger(execution)}"
                event="complete"/>
    </bpmn:extensionElements>
    <bpmn:incoming>incomingFlow</bpmn:incoming>
    <bpmn:outgoing>outGoingFlow</bpmn:outgoing>
</bpmn:userTask>

 

In my service

@Service
public class MySpringService {
public void methodToTrigger(DelegateExecution execution) {
// In task listener, I can get value
// But in execution listener, I cannot get value but can set process variable.
// In both cases, getVariableLocal always returns null. Object object = execution.getVariable(variableKey); log.debug(object); } }

But I solved like below.

// Specify variable scope as local
taskService.complete(task.getId(), taskParam, true);
@Service
public class MySpringService {

    public void methodToTrigger(DelegateExecution execution) {
        // Get variable local
        Object object = execution.getVariableLocal(variableKey);
        log.debug(object);
    }
}

Thank you for your help!