Skip to main content

Claim and complete a workflow task

List the workable tasks on a workflow, claim one, complete it with a named action and a document field update.

import sasvi

client = sasvi.SVIClient.from_env()

tasks = client.workflows.tasks.list(limit=10)
task = next(iter(tasks), None)
if task is None:
raise SystemExit("no workable tasks")

# Claim the task explicitly.
task.claim()

# Inspect the actions the task allows.
print([a.name for a in task.actions])

# Complete with one action plus a document field change.
result = task.complete(
action=task.action("Approve"),
document_field_values={"review_status": "APPROVED"},
)
print(repr(result))
# WorkflowTask(id='...', name='...', assignee='...')

task.action(name) looks up an action by display name. When the lookup fails it raises WorkflowOperationError listing the available names, which is why it beats next(a for a in task.actions if a.name == "Approve").

complete(action="Approve") does the same lookup for you. An unknown name raises before any request, so the task stays open.

Programmatic action discovery​

for action in task.actions:
print(action.name, [v.name for v in action.required_inputs])

required_inputs holds the variables the action expects. Supply them through entity_field_values= or process_variable_values=.

Release the claim​

If you change your mind:

task.release()
# Or, as an admin releasing someone else's claim:
task.release(administrator=True)

Async​

async with sasvi.SVIClient.from_env() as client:
tasks = await client.workflows.tasks.list_async(limit=10)
task = tasks[0]
await task.claim_async()
await task.complete_async(
action=task.action("Approve"),
document_field_values={"review_status": "APPROVED"},
)

Go further​