Update Variables in AEM Workflows?
Hello,
I am trying to update a variable in a Workflow using ECMA script. The script is very simple:
var workflowItemData = workItem.getWorkflowData();
var workflowData = workItem.getWorkflow().getWorkflowData();
if (workflowItemData.getPayloadType() == "JCR_PATH") {
var path = workflowItemData.getPayload().toString();
var metaPath = path.replace('renditions/original', 'metadata');
if (!workflowSession.getSession().itemExists(metaPath)) {
log.warn("Item does not exist: " + metaPath);
} else {
var metaNode = workflowSession.getSession().getItem(metaPath);
var size = metaNode.getProperty('dam:size');
//workflowData.getMetaDataMap().put("fSize", Number(size));
workflowItemData.getMetaDataMap().put("fSize", Number(size));
}
}
The "fSize" variable is added in the UI (initialized to 0). The script above is called in the "Process" step. I am attempting to use "fSize" in the "OR" branch; specifically if "fSize" is greater than a particular value, the first branch should be executed.
However, the first branch never executes, which leads me to suspect that the change made in the ECMA script is not being persisted. I confirmed via logging that the "fSize" key in the MetaDataMap has the expected value at the end of the ECMA script. I tried updating the meta data of both the workItem and workFlow but without success. I am following the documentation here: https://experienceleague.adobe.com/docs/experience-manager-65/developing/extending-aem/extending-workflows/using-variables-in-aem-workflows.html?lang=en#workflow-steps-without-support-for-variables


What am I missing? Any help would be appreciated!

