Start Workflow from REST and get the workflowInstanceId

When you start a workflow via REST (Context.StartWorkflow operation), how can you get the workflowInstanceId context variable populated by the operation? The REST call returns the JSON document, but not this context variable.

0 votes

1 answers

2903 views

ANSWER



One can either:

  • Write his/her own operation wich starts the workflow and returns the insctance id
  • Or one ca also use Studio to start the workflow and return the variable.

Here is my REST_StartBasicWorkflow chain:

Fetch > Context Document(s)

Workflow Context > Start Workflow
  id: BasicWorkflowTest

Execution Context > Restore input blob from a script
  script: return new org.nuxeo.ecm.core.api.impl.blob.StringBlob( "{\"workflowInstanceId\":\"" + Context["workflowInstanceId"] + "\"}" );

Then, calling the chain can be done like this:

http://{server}:{port}/nuxeo/api/v1/id/7474306b-dcc9-4023-a616-80a159ddf81c/@op/REST_StartBasicWorkflow

The result will be:

{ workflowInstanceId: "e947194d-8a1e-4d76-9da4-7807e2637d46" }

The external app would then store this Id, and can re-use it later. For example, to cancel the workflow:

POST http://{server}:{port}/nuxeo/site/api/v1/automation/Context.CancelWorkflow
Body: {"params":{"id": "e947194d-8a1e-4d76-9da4-7807e2637d46"}, "context":{}}

NOTE: Now, the document is not returned, but you can fill the StringBlob with any information form the document you need.

0 votes