How to have javascript code in the middle of AEM workflow ? | Community
Skip to main content
Mario248
Level 7
October 20, 2023
Solved

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

  • October 20, 2023
  • 2 replies
  • 1604 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Gaurav_Sachdeva_

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

 

Thanks

2 replies

Sudheer_Sundalam
Community Advisor
Community Advisor
October 20, 2023

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

Mario248
Mario248Author
Level 7
October 20, 2023

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

Gaurav_Sachdeva_
Level 3
October 20, 2023

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

Mario248
Mario248Author
Level 7
October 20, 2023

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 ?

Gaurav_Sachdeva_
Gaurav_Sachdeva_Accepted solution
Level 3
October 20, 2023

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

 

Thanks