How to programmatically advance to next step if a Participant hasn't acted on the workflow. | Community
Skip to main content
Level 3
June 22, 2023
Solved

How to programmatically advance to next step if a Participant hasn't acted on the workflow.

  • June 22, 2023
  • 2 replies
  • 1219 views

I have 3 steps in workflow model:

1. Participant

2. Participant

3. Process

If the participant hasn't acted on the workflow request from their inbox for some time period, I need to programmatically advance the workflow to the next step. Please help.

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 aanchal-sikka

Hello @rakesh_h2 

 

You can use the "Timeout Handler" configuration in participant step to achieve the same.

 

Set "Timeout Handler" = "Absolute Time Auto Advancer". And set "Timeout" to some value

 

https://experienceleague.adobe.com/docs/experience-manager-65/developing/extending-aem/extending-workflows/workflows-step-ref.html?lang=en#step-properties

2 replies

Tanika02
Level 7
June 22, 2023

Hello @rakesh_h2 - 

 

You can try below approach : 

 

 

import java.util.Calendar; import javax.jcr.Node; import com.adobe.granite.workflow.exec.WorkItem; import com.adobe.granite.workflow.exec.Workflow; import com.adobe.granite.workflow.exec.WorkflowData; import com.adobe.granite.workflow.exec.WorkflowException; import com.adobe.granite.workflow.exec.WorkflowProcess; import com.adobe.granite.workflow.metadata.MetaDataMap; import com.adobe.granite.workflow.WorkflowSession; import com.day.cq.workflow.WorkflowException; public class CustomWorkflowProcessStep implements WorkflowProcess { private static final String PARTICIPANT_ID = "participantId"; private static final String INACTIVITY_THRESHOLD = "inactivityThreshold"; @Override public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException { try { WorkflowData workflowData = workItem.getWorkflowData(); String participantId = metaDataMap.get(PARTICIPANT_ID, String.class); int inactivityThreshold = metaDataMap.get(INACTIVITY_THRESHOLD, Integer.class); Workflow workflow = workItem.getWorkflow(); String workflowInstancePath = workflow.getInitiator().concat("/").concat(workflow.getId()); Calendar currentTime = Calendar.getInstance(); Calendar participantStepTime = getParticipantStepTime(workflowSession, workflowInstancePath, participantId); if (participantStepTime != null) { long elapsedTimeInMillis = currentTime.getTimeInMillis() - participantStepTime.getTimeInMillis(); long inactivityThresholdInMillis = inactivityThreshold * 60 * 1000; if (elapsedTimeInMillis >= inactivityThresholdInMillis) { // Advance the workflow to the next step or process workflowSession.advance(workItem, null); return; } } } catch (Exception e) { throw new WorkflowException("Error executing custom workflow process step", e); } } private Calendar getParticipantStepTime(WorkflowSession workflowSession, String workflowInstancePath, String participantId) throws WorkflowException { try { Node workflowInstanceNode = workflowSession.getSession().getNode(workflowInstancePath); if (workflowInstanceNode.hasNode("history")) { Node historyNode = workflowInstanceNode.getNode("history"); NodeIterator iterator = historyNode.getNodes(); while (iterator.hasNext()) { Node historyEntryNode = iterator.nextNode(); String userId = historyEntryNode.getProperty("userId").getString(); if (participantId.equals(userId)) { Calendar stepTime = historyEntryNode.getProperty("time").getDate(); return stepTime; } } } } catch (Exception e) { throw new WorkflowException("Error retrieving participant step time", e); } return null; } }

 

rakesh_h2Author
Level 3
June 23, 2023

@tanika02 , Thanks Tanika for the answer. I should set this as the TimeoutHandler, right?

Tanika02
Level 7
June 23, 2023

Hello @rakesh_h2 - 

 

  • Yes, you can use the "Timeout Handler" configuration in the participant step to achieve a similar outcome.
  • By setting the "Timeout Handler" to "Absolute Time Auto Advancer" and specifying a value for the "Timeout" property, you can automatically advance the workflow if the participant hasn't acted within the specified time.

Here is how you can actually leverage Timeout Handler to auto advance the workflow to the next step if the user has not acted in a given timeframe : 

  1. Go to the workflow model.

  2. Locate the participant step for which you want to set the timeout.

  3. Edit the properties of the participant step.

  4. Set the "Timeout Handler" property to "Absolute Time Auto Advancer".

  5. Set the "Timeout" property to the desired value, specifying the duration after which the timeout should occur. This value is typically in milliseconds.

  6. Save the changes to the workflow model.

 

That's it!

aanchal-sikka
Community Advisor
aanchal-sikkaCommunity AdvisorAccepted solution
Community Advisor
June 22, 2023

Hello @rakesh_h2 

 

You can use the "Timeout Handler" configuration in participant step to achieve the same.

 

Set "Timeout Handler" = "Absolute Time Auto Advancer". And set "Timeout" to some value

 

https://experienceleague.adobe.com/docs/experience-manager-65/developing/extending-aem/extending-workflows/workflows-step-ref.html?lang=en#step-properties

Aanchal Sikka
rakesh_h2Author
Level 3
June 23, 2023

Thanks @aanchal-sikka 🙂