Write property to workflow payload at workflow dialog participant step | Community
Skip to main content
Level 3
January 17, 2023
Solved

Write property to workflow payload at workflow dialog participant step

  • January 17, 2023
  • 1 reply
  • 1219 views

Dear community fellows,

I'd created a custom workflow dialog to upload file onto a dam folder, and I'd like to store the path(write the property) on payload but couldn't make it.

I've tried to make it on the servlet that I use for uploading file, however, I cannot get the workitem from SlingHttpServletRequest, which is required for getting payload path. 

 

In previous cases, I made it by adding name properties on dialog node, as I finished the step I could write the property on payload.

Such as:

Datepicker

Dropdown select

For file uploading, I created my own input field, I guess that's the reason I couldn't rely on name property this time.

 

Any thoughts are welcome.

Thanks!

 

 

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 Anmol_Bhardwaj

Hi @yusheng ,

You are on the right path, you can easily get the path from the servlet. And set it in the payload

Try this:

@SlingServlet(paths = "/bin/myUploadServlet") public class MyUploadServlet extends SlingAllMethodsServlet { @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) { WorkflowSession workflowSession = request.getResourceResolver().adaptTo(WorkflowSession.class); String workItemId = request.getParameter("workItemId"); WorkItem workItem = workflowSession.getWorkItem(workItemId); if (workItem != null) { WorkflowData workflowData = workItem.getWorkflowData(); if (workflowData.getPayloadType().equals("JCR_PATH")) { String payloadPath = (String) workflowData.getPayload(); // set the path property on payload workflowData.getMetaDataMap().put("path", payloadPath); //save the changes workflowSession.updateWorkflowData(workItem, workflowData); } } } }

 

1 reply

Anmol_Bhardwaj
Community Advisor
Anmol_BhardwajCommunity AdvisorAccepted solution
Community Advisor
January 17, 2023

Hi @yusheng ,

You are on the right path, you can easily get the path from the servlet. And set it in the payload

Try this:

@SlingServlet(paths = "/bin/myUploadServlet") public class MyUploadServlet extends SlingAllMethodsServlet { @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) { WorkflowSession workflowSession = request.getResourceResolver().adaptTo(WorkflowSession.class); String workItemId = request.getParameter("workItemId"); WorkItem workItem = workflowSession.getWorkItem(workItemId); if (workItem != null) { WorkflowData workflowData = workItem.getWorkflowData(); if (workflowData.getPayloadType().equals("JCR_PATH")) { String payloadPath = (String) workflowData.getPayload(); // set the path property on payload workflowData.getMetaDataMap().put("path", payloadPath); //save the changes workflowSession.updateWorkflowData(workItem, workflowData); } } } }

 

YuShengAuthor
Level 3
January 18, 2023

Thank you @anmol_bhardwaj 

 

I've tried this and also found some examples similar to the snippet. Strangely, the workItemId from "request.getParameter("workItemId")" is null, and I also tried parameter "item" from another example but also get null.

 

Is it about the object which triggers the servlet?

my servlet is triggered as I click custom upload button, I tried trigger the servlet on OK button (.workitem-complete-dialog-submit) as well.

but still couldn't get the workItemId parameter from request.

 

Do you have any ideas about this?

Thanks! 

YuShengAuthor
Level 3
January 19, 2023

Indeed this snippet works if I call the servlet with "sling:resourceType" / "/bin/myServlet" like the reference below:

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-datasource-for-touch-ui-drop-down-based-on-component/td-p/270777 

 

But it doesn't work in my case.

Would open another thread for this and mark this solved.