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!
Solved! Go to Solution.
Views
Replies
Total Likes
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);
}
}
}
}
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);
}
}
}
}
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!
Indeed this snippet works if I call the servlet with "sling:resourceType" / "/bin/myServlet" like the reference below:
But it doesn't work in my case.
Would open another thread for this and mark this solved.
Views
Likes
Replies