Is it Possible to Change the Payload of Workflow
Hello.
I created a Workflow that launches in response to an Asset upload. This workflow renames the uploaded asset. However, this changes the payload (I.e. the original asset/path no longer exists). Thus I am running into issues when adding this step to the OOB "DAM Update Asset". Specifically, the Steps in that Workflow still try to use the "old" JCR path rather than the renamed one. This understandably generates an error.
I assume I would be able to call the OOB DAM Update Asset workflow from mine; however, Adobe advises against this and instead recommends updating the payload. However, I see no details on how one updates the payload. That is,I do not see how to update the Payload using any of the objects accessible from the ECMA script.
How can this be achieved?
For reference, here is my custom script:
var workflowData = workItem.getWorkflowData();
var pType = workflowData.getPayloadType();
if (workflowData.getPayloadType() == "JCR_PATH") {
var path = workflowData.getPayload().toString();
var parentPath = path.replace('/jcr:content/renditions/original', '');
if (workflowSession.getSession().itemExists(parentPath)) {
var replaceChars = new RegExp(" ", "g");
var node = workflowSession.getSession().getItem(path+"/jcr:content");
var pNode = workflowSession.getSession().getItem(parentPath);
var name = pNode.getPath();
var newName = name.replace(replaceChars, "_");
if(name != newName) {
workflowSession.getSession().move(name, newName);
pNode.save();
}
} else {
log.warn("Item does not exist: " + path);
}
}