Cokorda Raka
Cokorda Raka

Reputation: 4535

activity: how to know if an execution is linked to an instance of (sub)process?

I'm trying out this very simple scenario:

  1. Process 1 has two tasks (task A -> task B)
  2. Process 2 has one "call activity" block (calling Process 1).

So, I started Process 2. And it goes directly to a state where we have 2 executions:

  1. The one that directly maps to the instance of Process 2. Let's say: 123
  2. The one associated with the "call activity". Let's say: 456

The question is: how to easily find the task where Process 1 is currently at? (it should be Task A).

Well, I can do it with this REST queries:

  1. First I query all the executions that belong to Process 2: runtime/executions?processInstanceId=123

Here I get: [{id: 123}, {id: 456, activityId: "calling_subproc"}]

Well, I know that 456 is an execution of sub process, so the next query is:

  1. runtime/process-instances?superProcessInstanceId=123&includeProcessVariables=true

Here I get: [{id: 789, activityId: "task 1"}]

But..., I can do that because I know it is a sub-process, I designed the model. But ... otherwise, how will a program (ignorant of that fact) find out about it? There's nothing in the response from query #1 indicates that 456 is a subprocess (meaning I'll have to execute query #2..., rather than runtime/tasks?executionId=456&includeProcessVariables=true, which by-the-way gives me {data: [0], total: 0, start: 0, sort: "id", order: "asc", size: 0})

---- ADDITIONAL COMMENT : -----

I think the REST service runtime/executions should support "superExecutionId" parameter (e.g.: runtime/executions?superExecutionId=87519)... such that given the execution id (in the calling process), we can directly navigate to the spawned sub-process (the database structure supports that already):

enter image description here

Thanks in advance, Raka

Upvotes: 1

Views: 2955

Answers (1)

Greg Harley
Greg Harley

Reputation: 3240

This was a problem in a project I just finished. The solution/workaround was very much as listed in the above comment, we created a process variable to represent the "top level" process instance ID.

In order to make sure we didnt have to manually set this up for all called processes (i.e. didnt have to explicitly model the variable passing), we added a parse handler to add a start listener to automatically populate the variable when a called process is initiated.

Worked like a charm.

Upvotes: 3

Related Questions