Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Do we have an example of OR split in workflow using a process step instead of an ecma script ?

Avatar

Level 4

Do we have an example of OR split in workflow using a process step instead of an ecma script ?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @vishwanath881 
Unfortunately , I am not able to locate the dependency, I thought It would be part of uber jar.

 

However, I have also not tried it by myself.

 

you can try different approach

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowData;
import com.adobe.granite.workflow.exec.WorkflowProcess;

public class MyCustomProcessStep implements WorkflowProcess {
    @Override
    public void execute(WorkItem workItem, WorkflowSession workflowSession, WorkflowData workflowData) throws WorkflowException {
        // Your OR split logic here
        String condition1 = "your condition 1";  // Replace with your actual conditions
        String condition2 = "your condition 2";

        if (condition1.equals("true") || condition2.equals("true")) {
            // Route the workflow to the appropriate path based on the OR split conditions
            workflowSession.complete(workItem, "YOUR_NEXT_WORKFLOW_STEP");
        } else {
            // Handle the case when neither condition is met
            workflowSession.complete(workItem, "ANOTHER_NEXT_WORKFLOW_STEP");
        }
    }
}


Arun Patidar

View solution in original post

5 Replies

Avatar

Community Advisor
package com.example.workflow;

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.split.SplitResult;
import com.adobe.granite.workflow.split.impl.AbstractSplitter;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(service = AbstractSplitter.class, immediate = true)
public class OrSplitter extends AbstractSplitter {
    private static final Logger LOGGER = LoggerFactory.getLogger(OrSplitter.class);

    @Override
    public SplitResult doSplit(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
        // Retrieve the workflow variable "conditionVariable"
        String conditionVariable = (String) workItem.getWorkflowData().getMetaDataMap().get("conditionVariable");

        // Check the condition
        boolean conditionMet = "someValue".equals(conditionVariable);

        if (conditionMet) {
            LOGGER.info("Condition met. Proceeding along path A.");
            return new SplitResult("A");
        } else {
            LOGGER.info("Condition not met. Proceeding along path B.");
            return new SplitResult("B");
        }
    }
}


Arun Patidar

Avatar

Level 4

Hi @arunpatidar , Thanks for your response. However, I am unable to resolve dependencies for com.adobe.granite.workflow.split.* while compiling. Can you please share the dependency you are using? 

Avatar

Correct answer by
Community Advisor

Hi @vishwanath881 
Unfortunately , I am not able to locate the dependency, I thought It would be part of uber jar.

 

However, I have also not tried it by myself.

 

you can try different approach

import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.exec.WorkflowData;
import com.adobe.granite.workflow.exec.WorkflowProcess;

public class MyCustomProcessStep implements WorkflowProcess {
    @Override
    public void execute(WorkItem workItem, WorkflowSession workflowSession, WorkflowData workflowData) throws WorkflowException {
        // Your OR split logic here
        String condition1 = "your condition 1";  // Replace with your actual conditions
        String condition2 = "your condition 2";

        if (condition1.equals("true") || condition2.equals("true")) {
            // Route the workflow to the appropriate path based on the OR split conditions
            workflowSession.complete(workItem, "YOUR_NEXT_WORKFLOW_STEP");
        } else {
            // Handle the case when neither condition is met
            workflowSession.complete(workItem, "ANOTHER_NEXT_WORKFLOW_STEP");
        }
    }
}


Arun Patidar

Avatar

Administrator

@vishwanath881 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni