Workflow Context
Understanding the workflow context and how to access data between steps
Understanding Workflow Context
Every step in a Sample Workflow has access to a context object (ctx
) that provides essential information and utilities for the current workflow run. This context allows steps to communicate with each other, access user information, and interact with the backend system.
The WorkflowRunContext Class
The workflow context is implemented through the WorkflowRunContext
class, which provides the following key capabilities:
Properties
backend_token
: Authentication token for making API calls to the SampleHC backendcurrent_user
: Information about the user who initiated the workflow (dict withname
andemail
fields)resume_data
: Data used when resuming a suspended workflowscope
: Additional scoped data for the step that you’re on. For example, loops will havei
anditem
in scope.
Key Methods
get_step_result(step_id: str)
Retrieves the output from a previous step in the workflow by its step ID.
This method is essential for passing data between workflow steps, allowing later steps to build upon the results of earlier ones.
get_start_data()
Retrieves the initial data that was provided when the workflow was started.
Using Context in Workflow Steps
In Automated Steps
Best Practices
-
Step ID Consistency: Use clear, descriptive step IDs that make it easy to reference them in later steps.
-
Data Validation: Ensure the output is what you expect from previous steps before using it.
-
Context Security: The context includes authentication tokens, so be careful when logging or exposing context data.