Expand my Community achievements bar.

Workflow name in a servlet

Avatar

Level 2

Hi,

 

I have a workflow that includes a dialog participant step, and I am invoking a servlet to retrieve dropdown values. I have two different workflows calling the same servlet, and now I want to know the workflow name within the servlet. I tried the code below, but the workItem is always null.

Any help is appreciated. Thank you.

 

WorkflowSession workflowSession = request.getResourceResolver().adaptTo(WorkflowSession.class);
if (workflowSession != null) {
WorkItem workItem = (WorkItem) request.getAttribute("com.adobe.granite.workflow.exec.WorkItem");
if (workItem != null) {
Workflow workflow = workItem.getWorkflow();
WorkflowModel workflowModel = workflow.getWorkflowModel();
String workflowModelId = workflowModel.getId();
String workflowModelTitle = workflowModel.getTitle();

log.info("Workflow Model ID: {}", workflowModelId);
log.info("Workflow Model Title: {}", workflowModelTitle);
}
}

 

@EstebanBustamante  @arunpatidar 

6 Replies

Avatar

Community Advisor

Hi @Divya_T13 

Most probably its happening because workitem is not available in the servlet context .Few suggestions any possibility of passing this information as a request parameter to the servlet to identify the workflow, 

Servlet is invoked from UI or from inside any workflow itself , if from workflow try passing the workflow name in workflow metadata map and retrieve the same in the servlet. 

Avatar

Level 2

We are invoking servlet from a component dialog datasource node. And this component is included in Dialog path of Dynamic Participant step which will load when user takes action to complete that step. We will be able to get metadata map in any workflow implementation classes but not sure how to retrieve that in servlet.

Avatar

Level 2

How are you calling the servlet? What parameters do you pass to the servlet? You will get workflow session in the execute method in a workflow process but you might not get it in a servlet.

Why not pass the wf model as a param to the servlet?

Avatar

Level 2

We are invoking servlet from a component dialog datasource node and not passing any parameters. wf model is dynamic as we have same servlet invoked by different workflows.

Avatar

Level 2

Add requestpathinfo as a property in datasource node and make use of that to distinguish the workflow model. You can follow something like this - https://kiransg.com/tag/datasource-servlet/

Avatar

Community Advisor

Hi @Divya_T13 

You won't be able to get the workflow context in the servlet but you can check the request path in the servlet where you may utilize the workflow name/path to identofy which workflow model is invoking the servlet.



Arun Patidar