April 8, 2020
Estimated Post Reading Time ~

Workflow Dynamic Participant Step

Workflows in Adobe Experience Manager (AEM) has multiple participant steps like
  • Participant Step
  • Dynamic Participant Step
  • Dialog Participant Step
  • Form Participant Step
in which a user or a group will be assigned as a owner of that particular step. Each of these participant steps are used based on the usecase. Let us see in this blog on how to use and write a dynamic participant step.

Workflow Dynamic Participant Step is used when the user or a group to perform an activity in that step is selected automatically at run time based on some business logic unlike the user or a group are pre-selected. When we select the dynamic participant step in the workflow, we need to select the respective participant chooser from the drop down. There are many script/service available out of the box to select from or we can write our own participant chooser service as well which will be discussed further in this post.

Follow the below steps

1. Create a service class in the bundle (Sample shown below) and for a service to be identified as a participant step
  • implement ‘ParticipantStepChoose’ interface
  • override ‘getParticipant()’ method
  • Property name ‘ParticipantStepChooser.SERVICE_PROPERTY_LABEL’ to give the label that comes in the dropdown
@Component(immediate=true)
@Service
@Properties({
@Property(name = Constants.SERVICE_DESCRIPTION, value = “Sample Implementation of dynamic participant chooser.”),
@Property(name = ParticipantStepChooser.SERVICE_PROPERTY_LABEL, value = “Sample Workflow Participant Chooser”)
})

public class SampleParticipantStepChooserImpl implements ParticipantStepChooser {

private static final Logger logger = LoggerFactory.getLogger(SampleParticipantStepChooserImpl.class);

@Override
public String getParticipant(WorkItem workItem, WorkflowSession wfSession, MetaDataMap metaDataMap) throws WorkflowException {

String participant = “admin”;
Workflow wf = workItem.getWorkflow();
List<HistoryItem> wfHistory = wfSession.getHistory(wf);
if(!wfHistory.isEmpty()){
participant = “administrators”;
}else{
participant = “admin”;
}
logger.info(“####### Participant : ” + participant + ” ##############”);
return participant;
}

}

2. Build and deploy the bundle and make sure the bundle is in ‘active’ state

3. Create a workflow model, add a dynamic participant step in your workflow
Add Dynamic Participant Step

4. Click on the step and add the step properties
Add Step Properties

5. Click on the ‘Participant Chooser’ tab and see if the service you had created is visible and select the same. Click ok 
Select the participant step to choose script/servcie

6. Complete the workflow and ‘save’
Save the workflow

Now, the participant for this step would be derived out of logic from your service and you can control the same dynamically.

Important Notes:
1. Make sure you are importing the right packages based on the versions of AEM you are using
for AEM 5.6.1 and below use com.day.cq.workflow.* packages
for AEM 6.0 and above use com.adobe.granite.workflow.* packages

else you might not see the participant chooser service in the dropdown.

2. Deploy your service before you create your workflow.

3. On any change in your service and redeploy of the service, refresh your workflow model and reassign the service to the dynamic participant step to pick up the changes.

4. Any workflow instances that are running with the previous version, would not have the latest changes of the service or the workflow.

You can also refer the AEM Community article which gives the complete steps along with setting up the maven project here


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.