cancel
Showing results for 
Search instead for 
Did you mean: 

Have to query for process instance by business key and then for execution

yourboogieman
Champ in-the-making
Champ in-the-making
I have a use case that requires me to query for all receive tasks for a given process instance.  Intuitively, it seems I should be able to get this information in one query as follows:


// find the wait task that is awaiting a mailing response signal
Execution execution = runtimeService.createExecutionQuery()
      .activityId("awaitYearlyMailingResponse")
      .processInstanceBusinessKey(PROSPECT_MAILING_PROCESS_BUSINESS_KEY)
      .singleResult();

////////////////////////////////////////////////////////
// This fails, as execution is unexpectedly null here //
////////////////////////////////////////////////////////
assertNotNull(execution);

// deliver receive mailing response signal
runtimeService.signal(execution.getId(),
      Collections.singletonMap("askedOffMailingList", (Object) false));   // was not an ask-off-list response


Instead, the only way I found I could get the execution for this java receive task for the given process instance was with two separate queries as follows:


ProcessInstance processInstance = runtimeService
      .createProcessInstanceQuery()
      .processInstanceBusinessKey(PROSPECT_MAILING_PROCESS_BUSINESS_KEY)
      .singleResult();

// find the wait task that is awaiting a mailing response signal
Execution execution = runtimeService.createExecutionQuery()
      .activityId("awaitYearlyMailingResponse")
      .processInstanceBusinessKey(processInstance.getId())
      .singleResult();

//////////////////////////////////////////////////////////////////////////////////
// Returns expected result, but why should I have to do two queries? 😞 *pouts* //
//////////////////////////////////////////////////////////////////////////////////
assertNotNull(execution);

// deliver receive mailing response signal
runtimeService.signal(execution.getId(),
      Collections.singletonMap("askedOffMailingList", (Object) false));   // was not an ask-off-list response


Is there a way to get the desired result in one query?
10 REPLIES 10

Thanks for the update on this and sorry for the belated response.  I'm using version 5.14.  I'll look for the fix with 5.15 and, until then, I'll use the workaround you suggested.