Create Workflow Definition Link such as:
WorkflowDefinitionLink defnLink = WorkflowDefinitionLinkLocalServiceUtil .getDefaultWorkflowDefinitionLink(companyId, className, 0, 0);
To enable a workflow for custom entity, we have to make that entity an asset:
AssetEntryLocalServiceUtil.updateEntry(long userId, long groupId, String className, long classPK, null, null);
Start workflow instance:
WorkflowHandlerRegistryUtil.startWorkflowInstance( long companyId, long groupId, long userId, String className, long classPK, String className, ServiceContext serviceContext);
Once the workflow gets started, it will be into the initial state, mostly referred as CREATED state and it will be executed till the Task node of workflow. The user input will be required at Task node.
[2] Once the Task Performing Individual sends proposal to the Task Assigning Individual or Company and it gets approved, we have to move Entity state to “Approved” from “Start” state.
You can use Liferay API to move workflow task from one state/task to other state/task.
For moving to another Task node, first we need to complete existing workflow task. Workflow Task can be fetched from workflow logs. The code snippet to get the workflow task and complete that task is displayed below.
Workflow Instance is required to manage workflow operations:
WorkflowInstanceLink instanceLink = WorkflowInstanceLinkLocalServiceU-til.getWorkflowInstanceLink( long companyId, long groupId, String className, long classPK); WorkflowInstance instance = WorkflowInstanceManagerU-til.getWorkflowInstance (companyId, instanceLink.getWorkflowInstanceId());
How to get the latest workflow taskId from logs:
List<Integer> assignLogTypes = new ArrayList<>(); assignLogTypes.add(WorkflowLog.TASK_ASSIGN); List<WorkflowLog> wfAssignLogs = WorkflowLogManagerU-til.getWorkflowLogsByWorkflowInstance( companyId, instance.getWorkflowInstanceId(), assignLogTypes, QueryUtil.ALL_POS, QueryUtil.ALL_POS, WorkflowComparatorFacto-ryUtil.getLogCreateDateComparator(true)); long wfTaskId = wfAssignLogs.get(wfAssignLogs.size() – 1).getWorkflowTaskId(); WorkflowTask task = WorkflowTaskManagerUtil.getWorkflowTask(companyId, wfTaskId);
How to complete the workflow task:
It requires next transition name to execute other nodes.
WorkflowTaskManagerUtil.completeWorkflowTask(companyId, userId, task.getWorkflowTaskId(), transitionName, comment, instance.getWorkflowContext());