Hi, Is there a way to access workflow event type or workflow launcher details in backend java workflow process step?
Usecase: We have multiple workflow launchers (created, modified, deleted) using the same workflow model. Based on type of event, we need to take different action within the workflow process step.
We could not find a way to get the event type in the backend java class. Just wondering if anyone has done this before.
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
In that case I would not use the workflow launcher, but rather work either with a JCR Observation Listener or a Sling ResourceChangeEvent handler. They give you much more details about the type of action which happened, and then you can invoke the workflow and provide the details in the invocation.
WorkflowSession wfSession = ... WorkflowModel model = wfSession.getModel("/path/to/wf/model"); WorkflowData data = wfSession.newWorkflowData("JCR_PATH","/path/to/the/payload"); Map<String,Object> metadata = new HashMap<>(); metadata.put("reason","changed"); wfSession.startWorkflow(model, data, metadata);
With this approach you make the "reason" available in the workflow, and of course it should be related to the actual reason (this information is available from both types of event handling).
And then you can access this information like this in a workflow step:
[...] public class MyProcess implements WorkflowProcess { [...] execute(WorkItem item, WorkflowSession session, MetaDataMap args) { String reason = args.get("reason",String.class); } [...] }
Hi @beast42
Hope below code will be helpfull
List<HistoryItem> historyItems = workflowSession.getHistory(workitem.getWorkflow());
for (HistoryItem historyItem : historyItems) {
String itemType = historyItem.getWorkItem().getNode().getType();
String itemTitle = historyItem.getWorkItem().getNode().getTitle();
if ((null != itemType && itemType.equals(WorkflowNode.TYPE_PARTICIPANT))
&& (null != itemTitle && itemTitle.equalsIgnoreCase(McDConstants.STEP_NOTIFY_REVIEWER))) {
rejectionComment = historyItem.getComment();
break;
}
}
Thanks for your response.
Looks like the code snippet shared by you is for dynamic participant step. My use-case is different.
Hi,
no, this is not possible. The workflow does not know about the circumstances it was launched. What's the exact usecase you are working on?
Hi, Thanks for the response.
Exact use-case: We are syncing assets created under specific folder in DAM with a third party systems. We need to capture asset creation, modification and deletion events and call 3rd party REST API with required details.
We have multiple workflow launchers (created, modified, deleted) using the same workflow model. Based on type of event, we need to take different action within the workflow process step.
In that case I would not use the workflow launcher, but rather work either with a JCR Observation Listener or a Sling ResourceChangeEvent handler. They give you much more details about the type of action which happened, and then you can invoke the workflow and provide the details in the invocation.
WorkflowSession wfSession = ... WorkflowModel model = wfSession.getModel("/path/to/wf/model"); WorkflowData data = wfSession.newWorkflowData("JCR_PATH","/path/to/the/payload"); Map<String,Object> metadata = new HashMap<>(); metadata.put("reason","changed"); wfSession.startWorkflow(model, data, metadata);
With this approach you make the "reason" available in the workflow, and of course it should be related to the actual reason (this information is available from both types of event handling).
And then you can access this information like this in a workflow step:
[...] public class MyProcess implements WorkflowProcess { [...] execute(WorkItem item, WorkflowSession session, MetaDataMap args) { String reason = args.get("reason",String.class); } [...] }