Reputation: 904
I've followed this https://helpx.adobe.com/experience-manager/using/invoking-experience-manager-workflows-using.html and can invoke my workflow using the Java API. I'm trying to tweak this example so that I can start the workflow with MetaDataMap containing key value pairs for the steps to work with. The log message prints the key and value sets. But the steps in the workflow do not have this data. How do I pass a MetaDataMap to the workflow when starting it with the Java API?
@Override
public String StartWorkflow(String workflowName, String workflowContent, MetaDataMap metaMap) {
try
{
//Invoke the adaptTo method to create a Session
ResourceResolver resourceResolver = writeService.getResolver();
session = resourceResolver.adaptTo(Session.class);
//Create a workflow session
WorkflowSession wfSession = workflowService.getWorkflowSession(session);
// Get the workflow model
WorkflowModel wfModel = wfSession.getModel(workflowName);
// Get the workflow data
// The first param in the newWorkflowData method is the payloadType.
// Just a fancy name to let it know what type of workflow it is working with.
WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", workflowContent);
MetaDataMap mdp = wfData.getMetaDataMap();
for(Entry<String, Object> entry: metaMap.entrySet()){
log.info("WF Args entry="+ entry.getKey()+" "+entry.getValue());
mdp.put(entry.getKey(), entry.getValue());
}
// Run the Workflow.
wfSession.startWorkflow(wfModel, wfData, mdp);
return workflowName +" has been successfully invoked on this content: "+workflowContent ;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
Upvotes: 0
Views: 1568
Reputation: 1454
I believe you are trying to get your data from parameter of execute method - metaDataMap, but instead, get it from WorkItem object, like workItem.getWorkflowData().getMetaDataMap()
.
Upvotes: 1