Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Update Variables in AEM Workflows?

Avatar

Level 4

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...

 

 

KMarchewa_0-1684502327889.png

 

KMarchewa_1-1684502357548.png

 

 

What am I missing? Any help would be appreciated!

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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-...



Esteban Bustamante

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

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-...



Esteban Bustamante

Avatar

Level 4

Thanks for the replay. I tried adding that but it still is not working.

Avatar

Level 4

Never mind - user error on my part (had Branch 2 marked as default). Adding the "save()" call fixed it.

Avatar

Community Advisor

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/ 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/understanding-how-or-split... 

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

 

 

Shiv Prakash