cancel
Showing results for 
Search instead for 
Did you mean: 

Call Activity - Expression - How to

ginxo
Champ in-the-making
Champ in-the-making
Hello people,

I have a question about how to solve this situation I have in my hands. The thing is, I´m trying to define a custom process in order to repeat an specific functionality but with a dynamic expression specified by the "father" process. Let's call the custom process as "B" and the process that calls the B activity as "A", then… In my A process I call the B process specifying a target expression "customExpression" that lately is used in a Service Task of the B process. The thing is that I don't know how to use this "customExpression" in the Service Task.


In the A process

  <process id="A" name="A" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <callActivity id="callactivity1" name="Custom Service Task" calledElement="B">
      <extensionElements>
        <activiti:in sourceExpression="${customSpringService.execute(execution)}"></activiti:in>
      </extensionElements>
    </callActivity>
    <sequenceFlow id="flow10" sourceRef="startevent1" targetRef="callactivity1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow11" sourceRef="callactivity1" targetRef="endevent1"></sequenceFlow>
  </process>

In the B process

  <process id="B" name="B" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="serviceTask1" name="Service Task 1" activiti:expression="${customExpression}"></serviceTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow7" sourceRef="startevent1" targetRef="serviceTask1"></sequenceFlow>
    <sequenceFlow id="flow8" sourceRef="serviceTask1" targetRef="endevent1"></sequenceFlow>
  </process>


I hope to explain myself well…
Thanks a lot for your support.
7 REPLIES 7

ginxo
Champ in-the-making
Champ in-the-making

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,
check org.activiti.engine.test.bpmn.callactivity.CallActivityAdvancedTest#testCallSimpleSubProcessWithExpressions
In activiti source
Regards
Martin

ginxo
Champ in-the-making
Champ in-the-making
Thanks a lot Martin, but this is not exactly what I mean. I need to pass through the expression to be executed inside the subflow.
Cheers,
Kike.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Kike,

I need to pass through the expression to be executed inside the subflow

In that case I would pass it to the called subprocess as a string variable. In the subprocess (service or script) task, get expression manager from the org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl#getExpressionManager. Expression manager can create expression
org.activiti.engine.impl.el.ExpressionManager#createExpression(String expression). Expression can be evaluated in the context of e.g. execution org.activiti.engine.impl.el.ExpressionManager#createExpression.

Regards
Martin

ginxo
Champ in-the-making
Champ in-the-making
NICE! that's exactly what I need, let me try it and I'll confirm if your suggestion is solving my problem or not.

Thanks again Mark.
Kike.

ginxo
Champ in-the-making
Champ in-the-making
Mark,

Finally I tried it and it´s working perfectly…

This is the code of the service
<code>
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.impl.context.Context;
import org.springframework.stereotype.Component;

@Component("customService")
public class CustomService {

public void executeExpression(String expression, DelegateExecution execution) {
  Context.getProcessEngineConfiguration().getExpressionManager()
    .createExpression(expression).getValue(execution);
}
}
</code>

And this is the one from the service task
<blockcode>
    <serviceTask id="customServiceTask_execution" name="Custom Service Task" activiti:expression="${customService.executeExpression("${accountService.getAccount(execution)}", execution)}"></serviceTask>
</blockcode>

Instead of specifying "${accountService.getAccount(execution)}" directly as a method parameter I use a variable passed from the parent process.

Thanks a lot for your helping.
Kike.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Kike,

Glad to hear. 🙂

Martin