Skip to main content

Write Workflows Using Code

Workflows can be written in code, allowing the creation of dynamic workflows that can't be pre-defined. Support for defining workflows using code is part of all the supported SDKs.

Creating workflows in code

Here is the workflow that we are going to create using various language-specific SDKs in code:

user notification workflow

ConductorWorkflow<WorkflowInput> workflow = new ConductorWorkflow<>(executor);

SimpleTask getUserDetails = new SimpleTask("get_user_info", "get_user_info");
getUserDetails.input("userId", "${workflow.input.userId}");

SimpleTask sendEmail = new SimpleTask("send_email", "send_email");
// get user details user info, which contains the email field
sendEmail.input("email", "${}");

SimpleTask sendSMS = new SimpleTask("send_sms", "send_sms");
// get user details user info, which contains the phone Number field
sendSMS.input("phoneNumber", "${get_user_info.output.phoneNumber}");

Switch emailOrSMS = new Switch("emailorsms", "${workflow.input.notificationPref}")
.switchCase(, sendEmail)
.switchCase(, sendSMS);


//Execute the workflow and get the output
WorkflowInput input = new WorkflowInput("userA");
CompletableFuture<Workflow> workflowExecution = simpleWorkflow.executeDynamic(input);
Workflow workflowRun = workflowExecution.get(10, TimeUnit.SECONDS);