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-wor...
What am I missing? Any help would be appreciated!
Solved! Go to Solution.
Views
Replies
Total Likes
Are you saving (persisting) your changes? Try to add workflowSession.getSession().save() after you update the metadata
See here for more context https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/add-property-to-dam-asset-...
Are you saving (persisting) your changes? Try to add workflowSession.getSession().save() after you update the metadata
See here for more context https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/add-property-to-dam-asset-...
Thanks for the replay. I tried adding that but it still is not working.
Never mind - user error on my part (had Branch 2 marked as default). Adding the "save()" call fixed it.
Hi @KMarchewa ,
First Use Case : If you are selecting ECMA Script in OR Split, then you have to write check function which will return true or false at the basis of condition. In which branch it returns true that branch will be executed. (But only one branch will be execute). In your case check function will be on the basis of fSize.
For more details please check below references.
https://lhotsetechnologies.com/blog/or-split-in-workflow/
Second Use Case : When you are updating the MetaDataMap then you must have to save the sesson as below.
// Update the property value
metadataMap.put("propertyName", "newValue");
// Save the Workflow Session
workflowSession.getSession().save();
Regards,
Shiv