Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Workflow - Container step

Avatar

Level 4

Hi, has anyone passed data from Process to Container step in the workflow? I'm a bit struggling to achieve the same. Tried using the workItem object and adding to its MetaDataMap() but doesn't seem to work for me.

 

Process step:

 

 

public void execute (WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
throws WorkflowException {
try (ResourceResolver resolver = SystemResolverFactory.getSystemResolver(factory)) {
WorkflowData workflowData = workItem.getWorkflowData();
try {
workItem.getWorkflow().getMetaDataMap().put("custom_payload", "abc21324");
workItem.getMetaDataMap().put("custom_payload", "abc21324");
metaDataMap.put("test", "abc21324");

...

}

}

 

 

Container step:

 

 

public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap)
throws WorkflowException {
try (ResourceResolver resolver = SystemResolverFactory.getSystemResolver(factory)) {
WorkflowData workflowData = workItem.getWorkflowData();
log.error(workItem.getMetaDataMap().get("custom_payload").toString());
log.error(workItem.getWorkflow().getMetaDataMap().get("custom_payload").toString());

log.error(metaDataMap.get("test");

)

...
}

}

 

 

And my model has been designed like this:

 

 

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Page">
<jcr:content
cq:designPath="/libs/settings/wcm/designs/default"
cq:template="/libs/cq/workflow/templates/model"
jcr:isCheckedOut="{Boolean}true"
jcr:mixinTypes="[mix:versionable]"
jcr:primaryType="cq:PageContent"
jcr:title=""
jcr:uuid="25bb8fcc-0a79-4e05-bfb0"
sling:resourceType="cq/workflow/components/pages/model"
>
<flow
jcr:primaryType="nt:unstructured"
sling:resourceType="foundation/components/parsys">
<process
jcr:description="testststts"
jcr:primaryType="nt:unstructured"
jcr:title="test test"
sling:resourceType="cq/workflow/components/model/process">
<metaData
jcr:primaryType="nt:unstructured"
PROCESS="com.project.test.abc.process"
PROCESS_AUTO_ADVANCE="true"
timeoutMillis="3600000"/>
</process>
<container
jcr:created="{Date}2023-06-19T17:52:46.755+02:00"
jcr:createdBy="admin"
jcr:description="test description."
jcr:title="test title"
sling:resourceType="cq/workflow/components/model/container">
<metaData
jcr:primaryType="nt:unstructured"
CONTAINER="/var/workflow/models/path-to-container"
timeoutMillis="3600000"/>
</container>
</flow>
</jcr:content>
</jcr:root>

 

 

can someone let me know what I'm missing here? Thanks!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @rk_pandian 

 

In Container step can you try below.
String custom_payload = workItem.getWorkflowData().getMetaDataMap().get("custom_payload", String.class);

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @rk_pandian 

 

In Container step can you try below.
String custom_payload = workItem.getWorkflowData().getMetaDataMap().get("custom_payload", String.class);

Avatar

Level 4

Thank you Santhosh, I was missing out using the workItem.getWorkflowData() object, this solved my issue.

Avatar

Community Advisor

In the code snippets you provided, there seems to be an issue with how you are accessing the metadata map in the Process and Container steps of your custom workflow.

 

To pass data from a Process step to a Container step in AEM workflows, you can use the WorkflowData object and its metadata map. Here's how you can modify your code:

 

In the Process step:

 

 

public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
    WorkflowData workflowData = workItem.getWorkflowData();
    workflowData.getMetaDataMap().put("custom_payload", "abc21324");
}

 

 

 

In the Container step:

 

public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
WorkflowData workflowData = workItem.getWorkflowData();
String customPayload = workflowData.getMetaDataMap().get("custom_payload", String.class);
log.error(customPayload);
}

 

By using workflowData.getMetaDataMap() instead of workItem.getMetaDataMap() or workItem.getWorkflow().getMetaDataMap(), you can access and pass data between the Process and Container steps.

 

Also, make sure you have properly registered and implemented your custom Process and Container steps as OSGi services in AEM.

After making these changes, test your custom workflow to see if the data is successfully passed from the Process step to the Container step.

Avatar

Level 4

Thank you Tanika, I was missing out using the workItem.getWorkflowData() object, this solved my issue.