Call Activity being executed twice

In the model on which I am currently working, I have a service task, which needs to trigger multiple sub-process(another smaller workflow). To achieve this, I am using call activity. But it so happens that, the call-activity sub-process is being invoked twice the number of times.

Can you please suggest what might have been incorrect in my parent and sub-process models.
parent-workflow: process_workflow.bpmn (5.7 KB)
sub-process workflow: bsa_workflow.bpmn (6.8 KB)

Please note that,

  1. there are no overlapping sequence-flows, which might have been once of the reasons for this issue.
  2. Asynchronous-before has been added to call-activity task
  3. Asynchronous-before has been added to start-event and end-event in sub-process workflow(please suggest any best practice)

none of these above three points mitigated the issue.
Any queries feel free to ask?

Hi @Srinish and welcome to the forum!

I understand that the bsa_workflow.bpmn is executed twice as often as expected. However, I did not fully understand the logic of your process:
When you use call-activity, the process will be triggered automatically. There is no need to trigger the process from within a service task. So, if TriggerBSAJourneysAdapter triggers the service task, the call activity will trigger it again. As a result, you’d have two executions. Can you provide more information about your service task implementation?

However, without the implementation of your service tasks, I can only guess.

Also, I improved the diagrams a little bit: It’s considered a good practice, that every branch is either joined or ends in an end-event (This should, however, not resolve the issue).

bsa_workflow.bpmn (8.5 KB)
process_workflow.bpmn (6.3 KB)

@StephanHaarmann
here you go, attaching code-snippet of TriggerBSAJourneysAdapter implementation:

@Component
@Slf4j
public class TriggerBSAJourneysAdapter implements JavaDelegate {

    @Autowired
    private Gson gson;

    @Autowired
    private WorkflowService workflowService;

    @Override
    public void execute(final DelegateExecution execution) throws Exception {
        try {
            
            /*
            		****some processing perfomed here****
            */


            /*
            here, I need to invoke multiple call-activities i.e multiple BSA-Journey,
            thus, I have a loop, where I need to invoke the BSA-workflow manually
            due to fact that bsaStartAPIRequest object is different each iteration
            */
            for (BSAStartAPIRequest bsaStartAPIRequest : listOfBSAStartApiRequest) {
                HashMap<String, Object> map = new HashMap<>();
                final String data = gson.toJson(bsaStartAPIRequest, BSAStartAPIRequest.class);
                map.put("bsaStartAPIRequest", data);
                map.put("dataDir", dataDirPath);
                workflowService.startWorkflow("bsa_workflow", batchUuid, map);
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
    }
}

Feel free to suggest any better practises.

As espected, you’re calling the bsa workflow twice: once from the service task and once from the call activity. I recommend the following:

  1. Use the service task to prepare the data, i.e., to create a collection of baseStartApiRequests. But, do not call the subprocess in the service task.
  2. Instead, use the multi-instance call activity to call the bsa workflow once for each element in the collection. You can read more about multi instance activities here in our documentation. The advantage is that your diagram shows clearly that the process ought to be called multiple times, and you delegate the invocation to the process engine.

Please let me know whether this solves the issue.

1 Like

@StephanHaarmann
I am trying your suggestion of going with multi-instance(parallel) for the call activity(:handshake:)

But I am running into one minor issue, related to collection-variables.
It so happens, each iterating element, I am unable to access in the start-api service-task.

Please take a look at the bpmn files attached(have considered your recommendations) here:
bsa_workflow.bpmn (8.5 KB)
process_workflow.bpmn (6.4 KB)

TriggerBSAJourneysAdapter.java

@Component
@Slf4j
public class TriggerBSAJourneysAdapter implements JavaDelegate {

    @Autowired
    private Gson gson;

    @Autowired
    private WorkflowService workflowService;

    @Override
    public void execute(final DelegateExecution execution) throws Exception {
        try {
            
            /*
            		****some processing perfomed here****
            */


            /*
            here, I need to invoke multiple call-activities i.e multiple BSA-Journey,
            thus, I have a loop, where I need to invoke the BSA-workflow manually
            due to fact that bsaStartAPIRequest object is different each iteration
            */
            List<String> listOfBSAStartApiRequestAsString = new ArrayList<>();
            for (BSAStartAPIRequest bsaStartAPIRequest : listOfBSAStartApiRequest) {
                final String bsaStartApiRequestAsString = gson.toJson(bsaStartAPIRequest, BSAStartAPIRequest.class);
                listOfBSAStartApiRequestAsString.add(bsaStartApiRequestAsString);
            }
            execution.setVariable("listOfBSAStartApiRequestAsString", listOfBSAStartApiRequestAsString);

        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
    }
}

BSAStartAPIAdapter.java

@Slf4j
public class BSAStartAPIAdapter implements JavaDelegate {

    @Override
    public void execute(final DelegateExecution execution) throws Exception {
        try{
            final String batchUuid = execution.getBusinessKey();
            String bsaStartApiRequestAsString = (String) execution.getVariableLocal("bsaStartApiRequestAsString");
            BSAStartAPIRequest bsaStartAPIRequest = JSONUtil.fromJson(BSAStartAPIRequest.class,
                    bsaStartApiRequestAsString);
            log.info("reached BSAStartAPIAdapter...");
            log.info("bsaStartAPIRequest: {}", bsaStartAPIRequest);
        }catch(Exception e) {
            e.printStackTrace();
            throw new BpmnError("Error occurred in BSAStartAPIAdapter", e.getMessage());
        }
    }
}

have added the delegate impl classes also, please take a look at them
suggest any changes needed to access, multi-instance variables.
any modifications are welcomed.

There is only a tiny detail missing. Variables are not automatically forwarded to a call activity (and vice versa). You need to add an in mapping:


Here is the updated BPMN for reference process_workflow (2).bpmn (6.5 KB)

Thanks @StephanHaarmann that worked!!