executeEventByWorkitem(mainInstanceId, eventName, null, resultPayload);
}
public void executeEventByWorkitem(String mainInstanceId, String eventName, String triggerActivityTracingTag, ResultPayload resultPayload) throws RemoteException{
try{
ProcessInstance mainProcessInstance = getInstance(mainInstanceId);
//send message first
ProcessDefinition mainProcessDefinition = mainProcessInstance.getProcessDefinition();
EventMessagePayload eventMessagePayload = new EventMessagePayload();
eventMessagePayload.setEventName(eventName);
eventMessagePayload.setTriggerTracingTag(triggerActivityTracingTag);
mainProcessDefinition.fireMessage("event", mainProcessInstance, eventMessagePayload);
//get the initiated sub process instance
EventHandler[] ehs = getEventHandlersInAction(mainInstanceId);
EventHandler theEventHandler = null;
for(int i=0; i<ehs.length; i++){
if(ehs[i].getName().equals(eventName)){
theEventHandler = ehs[i];
break;
}
}
Activity handlerActivity = theEventHandler.getHandlerActivity();
HumanActivity humanActivity = null;
if(handlerActivity instanceof SubProcessActivity){
SubProcessActivity subProcessActivity = (SubProcessActivity)theEventHandler.getHandlerActivity();
Vector idVt = subProcessActivity.getSubprocessIds(mainProcessInstance);
String subInstanceId = (String)idVt.get(0);
ProcessInstance subProcessInstance = getInstance(subInstanceId);
completeInitiatorWorkitem(subProcessInstance, resultPayload);
return;