Expand my Community achievements bar.

SOLVED

Write property to workflow payload at workflow dialog participant step

Avatar

Level 4

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

YuSheng_0-1673955229214.png

YuSheng_1-1673955471683.png

Dropdown select

YuSheng_2-1673955636152.png

YuSheng_3-1673955817344.png

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

YuSheng_4-1673956331002.png

 

Any thoughts are welcome.

Thanks!

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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);
            }
        }
    }
}

 

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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);
            }
        }
    }
}

 

Avatar

Level 4

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.

YuSheng_0-1674011120559.png

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

 

Do you have any ideas about this?

Thanks! 

Avatar

Level 4

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-u... 

 

But it doesn't work in my case.

Would open another thread for this and mark this solved.