How to query the count of activity instances waiting at an intermediate catching event

Hi folks,

for some reason i need to get the count of activity instances waiting for the event correlation at an intermediate catching event in the context of multiinstance.

Under RuntimeService i have only found something like getActivityInstance, as the doc explained, this represents a activity instance(tree), but in the interface ActivityInstance there are only methods to get the child activityInstances but none for parent. I don’t actually understand it, without parent activity instance how could i get other instances at the same level?

Thanks,
Fan

Hi @fjiang,

you can use the following query to count your executions:

runtimeService.createExecutionQuery().activityId("intermediate-catch-event").count();
// or
runtimeService.createExecutionQuery().messageEventSubscriptionName("msg").count();
// add more criteria, e.g. processInstanceId(processInstanceId)

Does this help you?

Best regards,
Philipp

1 Like

Hi Philipp,

thanks for your reply! I prefer the first suggestion, but “intermediate-catch-event” isn’t an activityId but activity type. If it’s possible to query the activity type?

thanks

No, you can only query by the id of the activity. In my snippet, this should be an id.

Hi Philipp,

in other words, how can i get the current running activity’s type?

And if i use the activityId, by the following snippet which id should i use, the name or the id?

<bpmn:intermediateCatchEvent id=“IntermediateCatchEvent_00xioei” name=“PROVISIONING: Receive response”>
bpmn:incomingSequenceFlow_0n0n73y</bpmn:incoming>
bpmn:outgoingSequenceFlow_12o7a7k</bpmn:outgoing>
<bpmn:messageEventDefinition messageRef=“Message_0ew3wjw” />
</bpmn:intermediateCatchEvent>

You should use the id as the activity id -> IntermediateCatchEvent_00xioei.

You can get the type of an activity using the BPMN model API.
If you want to query by activity type then you can use the History Service HistoricActivityInstanceQuery.