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.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
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
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;
}
}
Hello @rakesh_h2 -
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 :
Go to the workflow model.
Locate the participant step for which you want to set the timeout.
Edit the properties of the participant step.
Set the "Timeout Handler" property to "Absolute Time Auto Advancer".
Set the "Timeout" property to the desired value, specifying the duration after which the timeout should occur. This value is typically in milliseconds.
Save the changes to the workflow model.
That's it!
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
Thanks @aanchal-sikka
Views
Likes
Replies