Expand my Community achievements bar.

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

How to have javascript code in the middle of AEM workflow ?

Avatar

Level 9

Team, I have an AEM workflow and it contains 4 Process Steps. After # process step 3, I want to run javascript code. Basically I want to execute JS code in middle of process step3 and process step4. Is there any other AEM workflow component available in this use case?

1 Accepted Solution

Avatar

Correct answer by
Level 4

@Mario248  you can call ECMA script from process step. Attaching screenshot for your reference to OOTB scripts, you can create custom script in apps/your-project and reference it.

Gaurav_Sachdeva__0-1697819263403.png

 

Thanks

View solution in original post

5 Replies

Avatar

Community Advisor

@Mario248 ,

 

JS code executes in the browser console during and after the page load completes. The workflow transition from one step to another happens in the AEM Server side.

Avatar

Level 9

Yeah, I actually want to generate a PDF using javascript in middle of workflow. Just want to know if this is feasible.

Avatar

Level 4

If you want to run JavaScript for your requirement you can write ECMA script and call it from the process step.

Sample ECMA script example:

 

var workflowData = workItem.getWorkflowData();
if (workflowData.getPayloadType() == "JCR_PATH") {
   // Write your custom code here.
    var path = workflowData.getPayload().toString();
    var node = workflowSession.getSession().getItem(path);
    node.setProperty("approved", args[0] == "true" ? true : false);
    node.save();
}

 

Thanks

Avatar

Level 9

Thank. I think I should go with ECMA script. But I see ECMA option only for "OR Split" component. I dont have any use case for OR Split. Is there any dedicated component for ECMA script ?

Avatar

Correct answer by
Level 4

@Mario248  you can call ECMA script from process step. Attaching screenshot for your reference to OOTB scripts, you can create custom script in apps/your-project and reference it.

Gaurav_Sachdeva__0-1697819263403.png

 

Thanks