Instances
When you start a Workflow, you create an Instance. That Instance contains data stored in fields and tracks the status of your automation workflow. Each Step in your Workflow becomes a Step in your Instance.
The Instances
client allows you to start and stop Instances, find and get data from your Instances and complete steps in your Instances. It provides the following methods:
Quickstart Example
/*
* This example demonstrates finding a Workflow, starting an Instance of
* that Workflow with some inputs, getting data from the Instance and
* finally completing a Step in the Instance.
*/
import org.catalytic.sdk.CatalyticClient;
import org.catalytic.sdk.entities.Workflow;
import org.catalytic.sdk.entities.WorkflowsPage;
import org.catalytic.sdk.entities.Field;
import java.util.List;
import java.util.ArrayList;
public class Program {
public static void main(String[] args) throws Exception {
// Create and initialize the Catalytic SDK Client
CatalyticClient catalytic = new CatalyticClient();
// Find workflows matching "Sdk Example Pushbot"
Workflow workflow = catalytic.workflows().find(
new Where().text().matches("SDK Example Workflow")
);
// `results` is a results page containing `workflows` and
// a `nextPageToken` you can use to page through results.
// We only expect one match for this example so we can simply
// get the first matching Workflow.
Where where = new Where().text().matches("SDK Example");
WorkflowsPage results = catalytic.workflows().find(where);
Workflow workflow = results.getWorkflows().get(0);
// Create fields to use when starting the instance
List<Field> fields = new ArrayList<>();
Field age = new Field("Age", 42);
Field name = new Field("Name", "Alice");
fields.add(age);
fields.add(name);
// Create an instance of the Workflow
Instance instance = catalytic.instances.start(
workflow.getId(),
"SDK Example - " + java.time.Instant.now().toString(),
"My Instance Example",
fields
);
System.out.println(instance.getName() + "has started with the status of " + instance.getStatus();
}
}
Updated almost 4 years ago