Workflows
This page is for the practitioner who needs workflow definitions, workflow instances, and bound
workflow tasks. All snippets below assume svi is an authenticated SVIClient.
Workflow instance states
Inspect the current phase via instance.state. The type is
Literal["RUNNING", "SUSPENDED", "COMPLETE", "CANCELED"]. The convenience
properties instance.is_active, instance.is_completed, instance.is_canceled
and instance.is_suspended do the comparison for you.
Before this example
Workflow names, instance ids, task ids, and user ids are deployment-specific. Use Discover Your Environment to find:
- a real workflow definition name
- a real workflow instance id or task id
- a real entity type and document id for workflow starts
- a real user id when you assign work
Workflow definitions
svi.workflows.definitions is the definition catalog. svi.admin.workflows is the same service
mounted under the configuration domain, so use whichever reads better in your script. Definitions
are authored in the VI designer. The API has no create operation, so the SDK only lists, looks up,
updates, reads revisions of and deletes the ones that already exist.
for definition in svi.workflows.definitions.list(limit=5):
print(definition.name, definition.entity_name, definition.enabled, definition.workflow_version)
# Narrow the listing with a raw filter expression.
for definition in svi.workflows.definitions.list_all(filter="eq(entityName,'investigation')"):
print(definition.id, definition.name)
Look one up by id or by exact machine name; both return None when nothing matches:
definition = svi.workflows.definitions.get_by_name(name="investigation_workflow")
if definition is not None:
same = svi.workflows.definitions.get(definition_id=definition.id, include_xml_model=True)
print(same.xml_model[:80] if same and same.xml_model else "no model requested")
print(definition.entity_defined_variable_names, [v.name for v in definition.variables])
Revisions
Every edit that changes the model creates a new revision. Revisions share the workflow name
and each carries its own id, which is why revisions() is keyed by name rather than by
definition id:
revisions = svi.workflows.definitions.revisions(name="investigation_workflow")
for revision in revisions:
print(revision.id, revision.workflow_version, revision.updated_at)
oldest = svi.workflows.definitions.revision(revision_id=revisions[-1].id)
revisions_all(name=...) pages exhaustively; filter= accepts a raw expression that is
combined with the name through and(...).
Delete
Edit a definition in the VI designer: the API has no update operation.
get on an older revision id answers HTTP 400, so read it with
revision(revision_id=...) instead.
svi.workflows.definitions.delete(definition_id="stale-definition-id")
delete raises WorkflowNotFoundError when the id is unknown.
List workflow instances
svi.workflows is runtime-focused and lists process instances:
instances = svi.workflows.list(limit=10)
for instance in instances:
print(instance.id, instance.workflow_name, instance.state)
You can switch between active, all, and completed views:
completed = svi.workflows.list(filter="completed", limit=10)
Start a workflow instance
Start by definition name or by definition id. Exactly one is required. The SDK resolves the definition, checks that the target document's entity type matches it, and builds the context payload for you:
instance = svi.workflows.start(
workflow_name="investigation_workflow",
document_id="4",
)
print(instance.id, instance.state)
pinned = svi.workflows.start(
definition_id=definition.id,
document_ref=("investigation", "4"),
variables={"WF_OWNER": "reviewer"},
)
A bound definition can start itself:
definition = svi.workflows.definitions.get_by_name(name="investigation_workflow")
if definition is not None:
instance = definition.start(document_id="4")
Or start from a bound document:
document = svi.documents.get(entity_type_name="investigation", document_id="4")
if document is not None:
instance = svi.workflows.start(workflow_name="investigation_workflow", document_ref=document)
body= remains the escape hatch for raw workflow context payloads; it cannot be combined with
document_ref, document_id or variables. An unknown name or id raises
WorkflowNotFoundError.
Inspect tasks for one instance
instance = svi.workflows.get(instance_id="process-123")
if instance is not None:
for task in instance.current_tasks():
print(task.id, task.name, task.assignee)
current_tasks() pages through the service until every current task of the instance is listed,
so a process whose parallel branches or group assignments fan out past one page comes back in
full. The tasks it returns carry the client's configured username, so task.claim() without an
assignee works on them as it does on a task from svi.workflows.tasks.get(...).
Work with tasks directly
Use the nested task namespace when you want global task operations:
tasks = svi.workflows.tasks.list(limit=10, include_only_workable_tasks=False)
for task in tasks:
print(task.id, task.name, task.assignee)
Claim and complete a task:
task = svi.workflows.tasks.get(task_id="12345")
if task is not None:
task.claim()
task.complete(action={"action": "approve"})
Complete a task and then patch fields on the underlying entity in the same call:
from sasvi import UserRef
task = svi.workflows.tasks.get(task_id="12345")
if task is not None:
task.complete(
action=task.actions[0],
document_field_values={
"manager_review_owner": UserRef("reviewer-id"),
"manager_review_summary": "<p>This is a manager summary</p>",
},
)
The SDK serializes UserRef(...), GroupRef(...), {"id": ..., "type": ...}, or (id, type)
tuples for VI chooser fields that expect user/group JSON payloads.
Completing a task cannot be undone, so complete() checks everything it can first. It builds
the action body, looks up the target document, reads the entity type, and validates the field
names before it sends the completion. An unknown field, a SOURCE entity type, or a missing
document raises with the task still open, and you can fix the call and try again.
The document write runs after the completion. If that write fails, complete() raises
WorkflowDocumentUpdateError. Its task_completed attribute is True, and task_id,
document_type and document_id name the task and the document. Do not call complete()
again, because the task is gone and the call returns 404. Retry the document update:
from sasvi.errors import WorkflowDocumentUpdateError
fields = {"manager_review_summary": "<p>This is a manager summary</p>"}
try:
task.complete(action=task.actions[0], document_field_values=fields)
except WorkflowDocumentUpdateError as exc:
document = svi.documents.get(entity_type_name=exc.document_type, document_id=exc.document_id)
document.update(fields)
Assign the task when your workflow hands work to a named user:
task = svi.workflows.tasks.get(task_id="12345")
if task is not None:
task.assign("reviewer")
print(task.assignee)
Release your own claim, or release another user's claim when you have workflow administrator rights:
task = svi.workflows.tasks.get(task_id="12345")
if task is not None:
task.release()
task.release(administrator=True)
Claim and release in batches
claim_many and release_many send the task ids to the selection endpoints in chunks of 100
(the endpoints' cap), in the order given. They return nothing, because the service reports no
per-task outcome. A failing chunk raises, and earlier chunks stay applied; the error message names
the failing chunk and how many ids went through before it. Unlike task.claim(), claim_many
never guesses an assignee.
task_ids = [task.id for task in svi.workflows.tasks.list(limit=200)]
svi.workflows.tasks.claim_many(task_ids=task_ids, assignee="reviewer")
svi.workflows.tasks.release_many(task_ids=task_ids, administrator=True)
client_application="mobile" changes the VI-Client-Application header the claim carries;
the default is "desktop".
Suspend, resume, cancel
Single instances, through the service or the bound instance (which refreshes itself):
svi.workflows.suspend(instance_id="process-123")
svi.workflows.resume(instance_id="process-123")
instance = svi.workflows.get(instance_id="process-123")
if instance is not None:
print(instance.suspend().is_suspended) # True
print(instance.resume().is_suspended) # False
instance.cancel()
Batches go through the selection endpoints in chunks of 100, order preserved. Every id is validated before the first request, an empty list sends nothing, and duplicates are sent as given:
active = [instance.id for instance in svi.workflows.list_all(filter="active")]
svi.workflows.suspend_many(instance_ids=active)
svi.workflows.resume_many(instance_ids=active)
svi.workflows.cancel_many(instance_ids=active[:10]) # irreversible
A missing process raises WorkflowNotFoundError. A process that cannot change state, such as one
you resume that is not suspended, raises WorkflowStateError. Any other refusal, HTTP 403 for
example, raises WorkflowOperationError with status_code and the response body in details.
When a batch fails part-way, the message says how many ids earlier chunks already applied, and
those are not rolled back.
View instance history
instance = svi.workflows.get(instance_id="process-123")
if instance is not None:
history = instance.history(limit=25)
for entry in history:
print(entry.task_name, entry.action, entry.completed_at)
Not wrapped on purpose
The Workflows API also has operations that act on every process at once, or on every process of an
entity type, with no scoping the SDK can check. They stay raw-only on svi.api.workflows:
DELETE /processes(cancel every process in the tenant)PUT /processes/suspendedandPUT /processes/resumed(every process)- the
/processes/entityName/{name}and/processes/entityInstanceId/{id}suspend, resume and delete families DELETE /workflows/entityName/{name}andDELETE /workflows/name/{name}(delete every definition for an entity type or name)
If you need one of these, call svi.api.workflows.<operation>() directly and scope it yourself.
The /settings/administrators* operations, which SAS marks internal, are not exposed at all:
neither the handwritten layer nor svi.api.workflows has a binding for them.
Go further
- Need query-side discovery first: Search guide
- Need the client layer explained: SVIClient and API layers
- Exact methods: Workflows API reference
- Mental model: Client model