How can I get the id of the workflow instance in workflow form?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
alekseybykov
Established Member II

How can I get the id of the workflow instance in workflow form?

Jump to solution

I have the FreeMarker template, which is the custom field for display some data about the business process.

Let's say, userdetails.ftl:

<@link href="${url.context}/res/components/workflow/workflow-form.css" group="workflow"/>
<#include "/org/alfresco/components/form/controls/common/utils.inc.ftl" />

<div class="form-field">
   <div id="...">
      <table id="..." class="yui-dt">
         <tr>
            <th class="yui-dt-liner">Field_1</th>
            <th class="yui-dt-liner">Field_2</th>
            <th class="yui-dt-liner">Field_3</th>
            <th class="yui-dt-liner">Field_4</th>
               ...
            <th class="yui-dt-liner">Field_N</th>
         </tr>
           ...
      </table>
   </div>
</div>

<script>

// Here I want to call REST back-end and parse the JSON response

</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Relevant part of the share-config-custom.xml:

<config evaluator="task-type" condition="mswf:reviewTask">
  <forms>
      <form>
          <field-visibility>
             <show id="mswf:userDetails" />
          </field-visibility>
          <appearance>
             <set id="userDetails" appearance="title" label="User Details" />
               <field id="mswf:userDetails" set="userDetails" label="User Details">
                    <control template="/org/alfresco/components/form/controls/workflow/userdetails.ftl" />
               </field>
             <field id="transitions" set="response" />
          </appearance>
      </form>
  </forms>
</config>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This template contains a table in which I would like to display the list of users who will participate in the business process (who was assigned).
 
Inside tags  <script></script> I want to invoke an embedded Alfresco WebScript (or my own - it's not important in this case) which returns me all the necessary information about the business process:

http://localhost:8080/alfresco/api/-default-/public/workflow/versions/1/processes/26205/variables‍

,where 26205 == id of the process instance.

I get the following:

{
   "list":{
      "pagination":{
         "count":36,
         "hasMoreItems":false,
         "totalItems":36,
         "skipCount":0,
         "maxItems":100
      },
      "entries":[
         {
            "entry":{
               "name":"bpm_packageActionGroup",
               "type":"d:text"
            }
         },
         {
            "entry":{
               "name":"mswf_approveCount",
               "type":"d:double",
               "value":0.0
            }
         },
         {
            "entry":{
               "name":"bpm_reassignable",
               "type":"d:boolean",
               "value":true
            }
         },
         {
            "entry":{
               "name":"bpm_priority",
               "type":"d:int",
               "value":2
            }
         },
         {
            "entry":{
               "name":"initiator",
               "type":"d:noderef",
               "value":"admin"
            }
         },
         {
            "entry":{
               "name":"mswf_actualRejectPercent",
               "type":"d:double",
               "value":0.0
            }
         },
         {
            "entry":{
               "name":"bpm_percentComplete",
               "type":"d:int",
               "value":0
            }
         },
         {
            "entry":{
               "name":"bpm_sendEMailNotifications",
               "type":"d:boolean",
               "value":false
            }
         },
         {
            "entry":{
               "name":"mswf_reviewOutcome",
               "type":"d:text",
               "value":"Reject"
            }
         },
         {
            "entry":{
               "name":"bpm_workflowPriority",
               "type":"d:int",
               "value":1
            }
         },
         {
            "entry":{
               "name":"bpm_hiddenTransitions",
               "type":"d:text"
            }
         },
         {
            "entry":{
               "name":"workflowinstanceid",
               "type":"d:text",
               "value":"activiti$26205"
            }
         },
         {
            "entry":{
               "name":"taskFormKey",
               "type":"d:text",
               "value":"mswf:activitiReviewTask"
            }
         },
         {
            "entry":{
               "name":"bpm_workflowDueDate",
               "type":"d:date",
               "value":"2017-03-12T20:00:00.000+0000"
            }
         },
         {
            "entry":{
               "name":"mswf_requiredPercent",
               "type":"d:double",
               "value":100.0
            }
         },
         {
            "entry":{
               "name":"mswf_reviewerCount",
               "type":"d:double",
               "value":2.0
            }
         },
         {
            "entry":{
               "name":"bpm_package",
               "type":"bpm:workflowPackage",
               "value":"workspace://SpacesStore/72086323-6c65-46f9-a1ad-8877630a6b40"
            }
         },
         {
            "entry":{
               "name":"mswf_actualPercent",
               "type":"d:double",
               "value":0.0
            }
         },
         {
            "entry":{
               "name":"nrOfActiveInstances",
               "type":"d:int",
               "value":2
            }
         },
         {
            "entry":{
               "name":"bpm_workflowDescription",
               "type":"d:text",
               "value":"message..."
            }
         },
         {
            "entry":{
               "name":"mswf_rejectCount",
               "type":"d:double",
               "value":0.0
            }
         },
         {
            "entry":{
               "name":"bpm_packageItemActionGroup",
               "type":"d:text",
               "value":"edit_package_item_actions"
            }
         },
         {
            "entry":{
               "name":"companyhome",
               "type":"d:noderef",
               "value":"workspace://SpacesStore/64f9f3c3-9227-425d-b336-bd255ab94c83"
            }
         },
         {
            "entry":{
               "name":"_startTaskCompleted",
               "type":"d:datetime",
               "value":"2017-03-13T07:03:12.612+0000"
            }
         },
         {
            "entry":{
               "name":"bpm_assignees",
               "type":"cm:person",
               "value":[
                  "first",
                  "second"
               ]
            }
         },
         {
            "entry":{
               "name":"loopCounter",
               "type":"d:int",
               "value":1
            }
         },
         {
            "entry":{
               "name":"bpm_description",
               "type":"d:text",
               "value":"message... "
            }
         },
         {
            "entry":{
               "name":"nrOfInstances",
               "type":"d:int",
               "value":2
            }
         },
         {
            "entry":{
               "name":"initiatorhome",
               "type":"d:noderef",
               "value":"workspace://SpacesStore/64f9f3c3-9227-425d-b336-bd255ab94c83"
            }
         },
         {
            "entry":{
               "name":"bpm_outcomePropertyName",
               "type":"d:qname",
               "value":"mswf:reviewOutcome"
            }
         },
         {
            "entry":{
               "name":"cm_name",
               "type":"d:text",
               "value":"Task"
            }
         },
         {
            "entry":{
               "name":"bpm_status",
               "type":"d:text",
               "value":"Not Yet Started"
            }
         },
         {
            "entry":{
               "name":"cancelled",
               "type":"d:boolean",
               "value":false
            }
         },
         {
            "entry":{
               "name":"reviewAssignee",
               "type":"d:noderef",
               "value":"second"
            }
         },
         {
            "entry":{
               "name":"mswf_requiredApprovePercent",
               "type":"d:int",
               "value":100
            }
         },
         {
            "entry":{
               "name":"nrOfCompletedInstances",
               "type":"d:int",
               "value":0
            }
         }
      ]
   }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

In addition to everything else I'm interested in this part:

"entry":{
   "name":"bpm_assignees",
   "type":"cm:person",
   "value":[
       "first",
       "second"
   ]
}‍‍‍‍‍‍‍‍

Here is the list of the users who will participate in the business process (in this specific instance).

To get all this information, I need to know the ID of the process instance (26205 in this case).

Can I determine this identifier in my userdetails.ftl template?..

I would be very grateful for the information. Thanks to all.

1 Solution

Accepted Solutions
mehe
Senior Member II

Re: How can I get the id of the workflow instance in workflow form?

Jump to solution

I am not shure about your intentions. Maybe you can retrieve the list of all processes with the REST endpoint of the Workflow-API (lookup api-explorer.alfresco.com for details) and iterate over the found process ids using the URL you already mentioned.

3 Replies
mehe
Senior Member II

Re: How can I get the id of the workflow instance in workflow form?

Jump to solution

I am not shure about your intentions. Maybe you can retrieve the list of all processes with the REST endpoint of the Workflow-API (lookup api-explorer.alfresco.com for details) and iterate over the found process ids using the URL you already mentioned.

alekseybykov
Established Member II

Re: How can I get the id of the workflow instance in workflow form?

Jump to solution

Thank you very much for your comment! Maybe you are right, but... Maybe I'm not quite precisely formulated the question. How can I iterate through all the IDs if I don't know the ID of the process that is currently running?.. When I have to stop, if I'll iterate through all the IDs?..

alekseybykov
Established Member II

Re: How can I get the id of the workflow instance in workflow form?

Jump to solution

How I imagine it. There may be many process instances. Each of them has a unique identifier. When some of the assigned user opens the form to approve or reject the document.. we don't know in which process instance it will work. But all the forms include a custom template - userdetails.ftl. Within this template (probably, that's what I want to find out) by using JavaScript is possible to obtain the ID of the current process instance. Then obtain the specific details about this concrete process.