<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Start Workflow from REST and get the workflowInstanceId in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/start-workflow-from-rest-and-get-the-workflowinstanceid/m-p/327841#M14842</link>
    <description>&lt;P&gt;When you start a workflow via REST (&lt;CODE&gt;Context.StartWorkflow&lt;/CODE&gt; operation), how can you get the &lt;CODE&gt;workflowInstanceId&lt;/CODE&gt; context variable populated by the operation? The REST call returns the JSON document, but not this context variable.&lt;/P&gt;</description>
    <pubDate>Sun, 20 Apr 2014 19:05:59 GMT</pubDate>
    <dc:creator>ThibArg_</dc:creator>
    <dc:date>2014-04-20T19:05:59Z</dc:date>
    <item>
      <title>Start Workflow from REST and get the workflowInstanceId</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/start-workflow-from-rest-and-get-the-workflowinstanceid/m-p/327841#M14842</link>
      <description>&lt;P&gt;When you start a workflow via REST (&lt;CODE&gt;Context.StartWorkflow&lt;/CODE&gt; operation), how can you get the &lt;CODE&gt;workflowInstanceId&lt;/CODE&gt; context variable populated by the operation? The REST call returns the JSON document, but not this context variable.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Apr 2014 19:05:59 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/start-workflow-from-rest-and-get-the-workflowinstanceid/m-p/327841#M14842</guid>
      <dc:creator>ThibArg_</dc:creator>
      <dc:date>2014-04-20T19:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: Start Workflow from REST and get the workflowInstanceId</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/start-workflow-from-rest-and-get-the-workflowinstanceid/m-p/327842#M14843</link>
      <description>&lt;P&gt;One can either:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Write his/her own operation wich starts the workflow and returns the insctance id&lt;/LI&gt;
&lt;LI&gt;Or one ca also use Studio to start the workflow and return the variable.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here is my REST_StartBasicWorkflow chain:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Fetch &amp;gt; Context Document(s)

Workflow Context &amp;gt; Start Workflow
  id: BasicWorkflowTest
    
Execution Context &amp;gt; Restore input blob from a script
  script: return new org.nuxeo.ecm.core.api.impl.blob.StringBlob( "{\"workflowInstanceId\":\"" + Context["workflowInstanceId"] + "\"}" );
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, calling the chain can be done like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;A href="http://{server}:{port}/nuxeo/api/v1/id/7474306b-dcc9-4023-a616-80a159ddf81c/@op/REST_StartBasicWorkflow" target="test_blank"&gt;http://{server}:{port}/nuxeo/api/v1/id/7474306b-dcc9-4023-a616-80a159ddf81c/@op/REST_StartBasicWorkflow&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result will be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;{ workflowInstanceId: "e947194d-8a1e-4d76-9da4-7807e2637d46" }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The external app would then store this Id, and can re-use it later. For example, to cancel the workflow:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;POST &lt;A href="http://{server}:{port}/nuxeo/site/api/v1/automation/Context.CancelWorkflow" target="test_blank"&gt;http://{server}:{port}/nuxeo/site/api/v1/automation/Context.CancelWorkflow&lt;/A&gt;
Body: {"params":{"id": "e947194d-8a1e-4d76-9da4-7807e2637d46"}, "context":{}}
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;NOTE&lt;/EM&gt;: Now, the document is not returned, but you can fill the StringBlob with any information form the document you need.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Apr 2014 19:10:00 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/start-workflow-from-rest-and-get-the-workflowinstanceid/m-p/327842#M14843</guid>
      <dc:creator>ThibArg_</dc:creator>
      <dc:date>2014-04-20T19:10:00Z</dc:date>
    </item>
  </channel>
</rss>

