Execute some logic before any PARTICIPANT step in a generic way | Community
Skip to main content
Level 2
October 16, 2015
Solved

Execute some logic before any PARTICIPANT step in a generic way

  • October 16, 2015
  • 3 replies
  • 766 views

Hi, I want to execute some code before the transition to any PARTICIPANT step to set up some properties in the workflow (mostly to be used in the email template)
I know that I can create a process step and execute it before any PARTICIPANT step but it doesn't seems to be the best way to solve this problem.

Another alternative I'm thinking is to create an EventHandler that set the properties in a NodeTransition to a PARTICIPANT step.
But I have two questions:
.- Is there any way to guarantee that this handler will be executed before the EMailNotificationService event handler?
If there is no way to guarantee this, is there any other way to achieve my requirement (execute some code before a PARTICIPANT step in a generic way)

.- For some reason when the new handler update the workflow the changes are not persisted.

I tried two alternatives but none are working: 

WorkItem currentItem = (WorkItem) event.getProperty(WorkflowEvent.WORK_ITEM); currentItem.getWorkflowData().getMetaDataMap().put("test", "test");

and:

String instanceId = (String) event.getProperty(WorkflowEvent.WORKFLOW_INSTANCE_ID); // wfSession came from an addmin session -> repository.loginAdministrative(null) Workflow workflow = wfSession.getWorkflow(instanceId); workflow.getWorkflowData().getMetaDataMap().put("test2", "test2"); wfSession.getSession().save();

Do I have to do something else to set up workflow properties?

Regards, Claudio.

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 Sham_HC

Oh i see.  Shouldn;t workflow creation one time & not regularly updated. Anyhow you can write a EventHandler for task event [1] and set service ranking properly so that get triggered before EmailNotification

[1]  https://dev.day.com/docs/en/cq/current/javadoc/com/adobe/granite/taskmanagement/TaskEvent.html

3 replies

Sham_HC
Level 10
October 16, 2015

create a process step before participant looks right way & what problem did you faced here & why do you think it does not meet your requirement? 

Alternative I could think is create dynamic participant step & in getParticipant() method before returning implement your logic. 

Level 2
October 16, 2015

The problem with the Process Step solution is that it forces us to add that step before all Participant steps. So anytime we add a Participant step (in any workflow) we have to add that step before, it doesn't feel the better way to do it. I prefer a more generic solution, where if there is a transition to a Participant step a code will be executed.

I guess that the dynamic participant step solution can work, but currently Dynamic Participant steps have some limitations (delegate doesn't work, dialogs neither). We don't use then unless we need a dynamic participant.

Sham_HC
Sham_HCAccepted solution
Level 10
October 16, 2015

Oh i see.  Shouldn;t workflow creation one time & not regularly updated. Anyhow you can write a EventHandler for task event [1] and set service ranking properly so that get triggered before EmailNotification

[1]  https://dev.day.com/docs/en/cq/current/javadoc/com/adobe/granite/taskmanagement/TaskEvent.html