如何以工作流形式获取工作流实例的ID?

时间:2017-03-13 14:36:46

标签: alfresco activiti alfresco-webscripts

我有FreeMarker模板,这是用于显示有关业务流程的一些数据的自定义字段。

让我们说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>

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>

此模板包含一个表格,我希望在该表格中显示将参与业务流程的用户列表(已分配的用户)。

内部标记<script></script>我想调用嵌入式Alfresco WebScript(或者我自己的 - 在这种情况下它并不重要),它返回了有关业务流程的所有必要信息:

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

,流程实例的26205 == id

我得到以下内容:

{
   "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
            }
         }
      ]
   }
}

除了我对此部分感兴趣的所有内容之外:

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

以下是参与业务流程的用户列表(在此特定实例中)。

要获取所有这些信息,我需要知道流程实例的ID(在这种情况下为26205)。

我可以在userdetails.ftl模板中确定此标识符吗?

我将非常感谢这些信息。谢谢大家。

1 个答案:

答案 0 :(得分:1)

工作流程ID确实是您工作流程中可用的变量之一,我建议您使用隐藏的表单控件hidden.ftl将其添加到表单中,然后从您的JS片段中使用dom访问隐藏的表单按ID /名称输入,并在您认为合适的逻辑中使用它!