<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Synchronized workflow instance creation and reached task retrieval</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=117932145" />
  <subtitle>Synchronized workflow instance creation and reached task retrieval</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=117932145</id>
  <updated>2026-04-05T02:42:10Z</updated>
  <dc:date>2026-04-05T02:42:10Z</dc:date>
  <entry>
    <title>RE: Synchronized workflow instance creation and reached task retrieval</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117956675" />
    <author>
      <name>Ruben Lopez</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117956675</id>
    <updated>2019-12-03T12:19:39Z</updated>
    <published>2019-12-03T12:19:39Z</published>
    <summary type="html">Sure! so the code is quite simple.We have an initial method where my entity linked to the workflow (ServiceDetails) is saved and triggers the workflow:&lt;br /&gt;&lt;br /&gt;public ServiceDetails saveAndInitiateWorkflow(ServiceDetails serviceDetails, ServiceContext serviceContext) throws PortalException{&lt;br /&gt;                   serviceContext.setAttribute(&amp;#34;workflowContext&amp;#34;, serviceWorkflowServiceUtil.createWorkflowContext());&lt;br /&gt;    &lt;br /&gt;              ServiceDetails updatedServiceDetails = updateServiceDetails(serviceContext.getUserId(), serviceDetails, WorkflowConstants.STATUS_PENDING);&lt;br /&gt;&lt;br /&gt;              serviceDetailsWorkflowService.initiateServiceDetailsWorkflow(serviceContext.getUserId(), updatedServiceDetails, serviceContext);&lt;br /&gt;&lt;br /&gt;              return updatedServiceDetails;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Then, when the specific workflow state is reached, the onEntry action triggers a call to another method to assign the task to the current user. This never actually happens because the task retrieval fails before it can be assigned.&lt;br /&gt;&lt;br /&gt;public WorkflowTask assignServiceDetailsTaskToUser(long companyId, long userId, long serviceDetailsId, long assigneeUserId) throws PortalException {&lt;br /&gt;                  Optional&amp;lt;WorkflowTask&amp;gt; workflowTask = workflowTaskService.getWorkflowTask(companyId, serviceDetailsId, ServiceDetails.class.getName(), false);&lt;br /&gt;&lt;br /&gt;                  WorkflowTaskManagerUtil.assignWorkflowTaskToUser(companyId, userId, workflowTask.get().getWorkflowTaskId(), assigneeUserId, StringPool.BLANK, null, null);&lt;br /&gt;&lt;br /&gt;                  return workflowTask.get();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The workflowTaskService.getWorkflowTask is a custom method that executes a dynamic query to hit the database directly and avoid the index used by the WorkflowTaskManagerUtil search method.&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve also tried calling the method in the onExit event of the workflow state, but the result is the same, the task hasn&amp;#39;t been created yet. I think the transaction is not committed in time, but using the TransactionCommitCallbackUtil to add a callback didn&amp;#39;t work either.&lt;br /&gt;&lt;br /&gt;Any ideas?? thanks!</summary>
    <dc:creator>Ruben Lopez</dc:creator>
    <dc:date>2019-12-03T12:19:39Z</dc:date>
  </entry>
  <entry>
    <title>RE: Synchronized workflow instance creation and reached task retrieval</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117935967" />
    <author>
      <name>Fernando Fernandez</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117935967</id>
    <updated>2019-11-29T16:35:21Z</updated>
    <published>2019-11-29T16:35:21Z</published>
    <summary type="html">That is strange. Don&amp;#39;t you want to share the code that&amp;#39;s being called?</summary>
    <dc:creator>Fernando Fernandez</dc:creator>
    <dc:date>2019-11-29T16:35:21Z</dc:date>
  </entry>
  <entry>
    <title>RE: Synchronized workflow instance creation and reached task retrieval</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117935631" />
    <author>
      <name>Ruben Lopez</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117935631</id>
    <updated>2019-11-29T16:17:37Z</updated>
    <published>2019-11-29T16:17:37Z</published>
    <summary type="html">Unfortunately that doesn&amp;#39;t work for me either. I need to retrieve the WorkflowTask when the &amp;#34;on entry&amp;#34; event calls my code, but it seems that it doesn&amp;#39;t exist yet in the database.</summary>
    <dc:creator>Ruben Lopez</dc:creator>
    <dc:date>2019-11-29T16:17:37Z</dc:date>
  </entry>
  <entry>
    <title>RE: Synchronized workflow instance creation and reached task retrieval</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117933510" />
    <author>
      <name>Ruben Lopez</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117933510</id>
    <updated>2019-11-29T13:34:42Z</updated>
    <published>2019-11-29T13:34:42Z</published>
    <summary type="html">Thanks Fernando!&lt;br /&gt;that&amp;#39;s what I did using a monitor to stop the main thread while the task wasn&amp;#39;t reached.&lt;br /&gt;But actually I think it could work if I separate out the code that starts the workflow from the one that&amp;#39;s executed after the task finishes and I use a condition on the entry action (as it shouldn&amp;#39;t be executed always).&lt;br /&gt;I&amp;#39;ll give it a try and let you know</summary>
    <dc:creator>Ruben Lopez</dc:creator>
    <dc:date>2019-11-29T13:34:42Z</dc:date>
  </entry>
  <entry>
    <title>RE: Synchronized workflow instance creation and reached task retrieval</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117932818" />
    <author>
      <name>Fernando Fernandez</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117932818</id>
    <updated>2019-11-29T13:08:32Z</updated>
    <published>2019-11-29T13:08:32Z</published>
    <summary type="html">Hi Ruben,&lt;br /&gt;&lt;br /&gt;If I understood correctly, you&amp;#39;re starting the workflow and need to know where it stopped.&lt;br /&gt;I would do this by defining a entry action in the tasks and calling some java code of yours.&lt;br /&gt;&lt;br /&gt;Fernando</summary>
    <dc:creator>Fernando Fernandez</dc:creator>
    <dc:date>2019-11-29T13:08:32Z</dc:date>
  </entry>
  <entry>
    <title>Synchronized workflow instance creation and reached task retrieval</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117932144" />
    <author>
      <name>Ruben Lopez</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=117932144</id>
    <updated>2019-11-29T12:57:33Z</updated>
    <published>2019-11-29T12:57:33Z</published>
    <summary type="html">Hi!&lt;br /&gt;&lt;br /&gt;I have a custom entity linked to a workflow which reaches a specific task after an initial condition check&lt;br /&gt;&lt;br /&gt;I&amp;#39;m trying to trigger the workflow and retrieve the final task reached in that process in a single step (method), but every time I try to retrieve the task from the database, it can&amp;#39;t be found because it&amp;#39;s not created in time.I&amp;#39;m using a dynamic query to hit the database as the WorkflowTaskManagerUtil.search didn&amp;#39;t work either.&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve tried multiple ways to do this without success, i.e.: using java monitors and notifying when the workflow task is entered, again with monitors using a MessageListener to capture the KALEO_GRAPH_WALKER message to notify  the awaiting thread and even registering a commit callback. None of these has worked.&lt;br /&gt;&lt;br /&gt;Has anybody found a way to do this or to synchronize the workflow execution somehow?&lt;br /&gt;&lt;br /&gt;Thanks!</summary>
    <dc:creator>Ruben Lopez</dc:creator>
    <dc:date>2019-11-29T12:57:33Z</dc:date>
  </entry>
</feed>
