Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Synchronized workflow instance creation and reached task retrieval
Hi!
I have a custom entity linked to a workflow which reaches a specific task after an initial condition check
I'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't be found because it's not created in time.I'm using a dynamic query to hit the database as the WorkflowTaskManagerUtil.search didn't work either.
I'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.
Has anybody found a way to do this or to synchronize the workflow execution somehow?
Thanks!
I have a custom entity linked to a workflow which reaches a specific task after an initial condition check
I'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't be found because it's not created in time.I'm using a dynamic query to hit the database as the WorkflowTaskManagerUtil.search didn't work either.
I'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.
Has anybody found a way to do this or to synchronize the workflow execution somehow?
Thanks!
Hi Ruben,
If I understood correctly, you're starting the workflow and need to know where it stopped.
I would do this by defining a entry action in the tasks and calling some java code of yours.
Fernando
If I understood correctly, you're starting the workflow and need to know where it stopped.
I would do this by defining a entry action in the tasks and calling some java code of yours.
Fernando
Thanks Fernando!
that's what I did using a monitor to stop the main thread while the task wasn't reached.
But actually I think it could work if I separate out the code that starts the workflow from the one that's executed after the task finishes and I use a condition on the entry action (as it shouldn't be executed always).
I'll give it a try and let you know
that's what I did using a monitor to stop the main thread while the task wasn't reached.
But actually I think it could work if I separate out the code that starts the workflow from the one that's executed after the task finishes and I use a condition on the entry action (as it shouldn't be executed always).
I'll give it a try and let you know
Unfortunately that doesn't work for me either. I need to retrieve the WorkflowTask when the "on entry" event calls my code, but it seems that it doesn't exist yet in the database.
That is strange. Don't you want to share the code that's being called?
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:
public ServiceDetails saveAndInitiateWorkflow(ServiceDetails serviceDetails, ServiceContext serviceContext) throws PortalException{
serviceContext.setAttribute("workflowContext", serviceWorkflowServiceUtil.createWorkflowContext());
ServiceDetails updatedServiceDetails = updateServiceDetails(serviceContext.getUserId(), serviceDetails, WorkflowConstants.STATUS_PENDING);
serviceDetailsWorkflowService.initiateServiceDetailsWorkflow(serviceContext.getUserId(), updatedServiceDetails, serviceContext);
return updatedServiceDetails;
}
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.
public WorkflowTask assignServiceDetailsTaskToUser(long companyId, long userId, long serviceDetailsId, long assigneeUserId) throws PortalException {
Optional<WorkflowTask> workflowTask = workflowTaskService.getWorkflowTask(companyId, serviceDetailsId, ServiceDetails.class.getName(), false);
WorkflowTaskManagerUtil.assignWorkflowTaskToUser(companyId, userId, workflowTask.get().getWorkflowTaskId(), assigneeUserId, StringPool.BLANK, null, null);
return workflowTask.get();
}
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.
I've also tried calling the method in the onExit event of the workflow state, but the result is the same, the task hasn't been created yet. I think the transaction is not committed in time, but using the TransactionCommitCallbackUtil to add a callback didn't work either.
Any ideas?? thanks!
public ServiceDetails saveAndInitiateWorkflow(ServiceDetails serviceDetails, ServiceContext serviceContext) throws PortalException{
serviceContext.setAttribute("workflowContext", serviceWorkflowServiceUtil.createWorkflowContext());
ServiceDetails updatedServiceDetails = updateServiceDetails(serviceContext.getUserId(), serviceDetails, WorkflowConstants.STATUS_PENDING);
serviceDetailsWorkflowService.initiateServiceDetailsWorkflow(serviceContext.getUserId(), updatedServiceDetails, serviceContext);
return updatedServiceDetails;
}
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.
public WorkflowTask assignServiceDetailsTaskToUser(long companyId, long userId, long serviceDetailsId, long assigneeUserId) throws PortalException {
Optional<WorkflowTask> workflowTask = workflowTaskService.getWorkflowTask(companyId, serviceDetailsId, ServiceDetails.class.getName(), false);
WorkflowTaskManagerUtil.assignWorkflowTaskToUser(companyId, userId, workflowTask.get().getWorkflowTaskId(), assigneeUserId, StringPool.BLANK, null, null);
return workflowTask.get();
}
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.
I've also tried calling the method in the onExit event of the workflow state, but the result is the same, the task hasn't been created yet. I think the transaction is not committed in time, but using the TransactionCommitCallbackUtil to add a callback didn't work either.
Any ideas?? thanks!
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™