Workflow name in a servlet | Community
Skip to main content
January 7, 2025
Solved

Workflow name in a servlet

  • January 7, 2025
  • 3 replies
  • 1082 views

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 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi @divyat3 

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.

3 replies

sherinregi-1
Community Advisor
Community Advisor
January 7, 2025

Hi @divyat3 

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. 

DivyaT3Author
January 8, 2025

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.

SreenivasBr
Level 4
January 7, 2025

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?

DivyaT3Author
January 8, 2025

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.

SreenivasBr
Level 4
January 8, 2025

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/

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
January 7, 2025

Hi @divyat3 

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
DivyaT3Author
January 9, 2025

Hi @arunpatidar 

 

Thank you so much for your inputs.

originalURI, embedded within a series of request wrappers, contains the complete URL along with query parameters: /{contextpath}/libs/cq/inbox/content/inbox/dialogs/dialogInjectionRender.html?item=%2Fvar%2Fworkflow%2Finstances%2Fserver0%2F2025-01-06%2Ftest-custom-approval-workflow_27%2FworkItems%2Fnode2_var_workflow_instances_server0_2025-01-06_test-custom-approval-workflow_27&ch_ck=1736406875098.

 

In the servlet, we can identify the workflow name (wfname) through request.getQueryString()