本文介绍了Activiti工作流程:从StartTask设置方面的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在启动表单的文本字段中设置一个值,然后将其用于其他几个任务。为此,我使用了一个方面,尝试将数据发送到执行变量,然后将其拉低。

I need to set a value from a text field on my start form and then pull this information on several other tasks. To do this, I'm using an aspect and trying to send the data up to the execution variable, and then pull it down.

问题是我无法发送从起始表单到执行变量的值。现在,Share只会说无法启动工作流程。

The problem is that I cannot send the value from the start form to the execution variable. As it is now, Share will just say that the workflow cannot be started.

我正在使用Alfresco 4.2.f社区版。

I am using Alfresco 4.2.f Community edition.

开始事件在BPMN中的定义如下: :

The start event is defined in the BPMN as follows:

<startEvent id="start" name="Start Delivery Ticket Workflow" activiti:initiator="initiatorUserName" activiti:formKey="deliveryTicketWorkflow:start">
  <documentation>Project Manager initiates workflow. A customer purchase order is provided, along with the specific line items for the delivery ticket.</documentation>
  <extensionElements>
    <activiti:executionListener class="org.alfresco.repo.workflow.activiti.listener.ExecutionListener" event="start">
      <activiti:field name="script">
        <activiti:string><![CDATA[  
             execution.setVariable('deliveryTicketWorkflow_requestdetailstext', task.getVariable('deliveryTicketWorkflow_requestdetailstext'));;
         ]]></activiti:string>
      </activiti:field>
    </activiti:executionListener>
  </extensionElements> 
</startEvent>

我模型的相关部分是:

<type name="deliveryTicketWorkflow:start">
  <parent>bpm:startTask</parent>
  <properties />
  <associations />
  <overrides />
  <mandatory-aspects>
    <aspect>deliveryTicketWorkflow:requestdetails</aspect>
  </mandatory-aspects>
</type>
[...]
 <aspect name="deliveryTicketWorkflow:requestdetails">
  <properties>
    <property name="deliveryTicketWorkflow:requestdetailstext">
      <title>Specific Details</title>
      <type>d:text</type>
      <mandatory>true</mandatory>
      <multiple>false</multiple>
    </property>
  </properties>
</aspect>

在配置中:

<config condition="deliveryTicketWorkflow:start" evaluator="task-type">
    <forms>
        <form>
            <field-visibility>
                <show id="packageItems"/>
                <show id="deliveryTicketWorkflow:requestdetailstext"/>
                <show id="transitions"/>
            </field-visibility>
            <appearance>
                <set appearance="title" label-id="Prepare Delivery Ticket" id="info"/>
                <field set="info" id="packageItems"/>
                <field set="info" label-id="Request Details" id="deliveryTicketWorkflow:requestdetailstext">
                    <control template="/org/alfresco/components/form/controls/info.ftl"/>
                </field>
                <set id="response"/>
                <field set="response" id="transitions"/>
            </appearance>
        </form>
    </forms>
</config>
[...]
<config condition="activiti$deliveryTicketWorkflow" evaluator="string-compare">
    <forms>
        <form>
            <field-visibility>
                <show id="bpm:workflowPriority"/>
                <show id="packageItems"/>
                <show id="deliveryTicketWorkflow:requestdetails"/>
                <show id="transitions"/>
                <show id="deliveryTicketWorkflow:approveRejectOutcome"/>
            </field-visibility>
            <appearance>
                <set appearance="title" label-id="Request Delivery Ticket" id="info"/>
                <field set="info" label-id="workflow.field.priority" id="bpm:workflowPriority">
                    <control template="/org/alfresco/components/form/controls/workflow/priority.ftl"/>
                </field>
                <field set="info" id="packageItems"/>
                <field set="info" label-id="Request Details" id="deliveryTicketWorkflow:requestdetails">
                    <control template="/org/alfresco/components/form/controls/textarea.ftl"/>
                </field>
                <set id="response"/>
                <field set="response" id="approveRejectOutcome">
                    <control template="/org/alfresco/components/form/controls/workflow/activiti-transitions.ftl"/>
                </field>
                <field set="response" id="transitions"/>
            </appearance>
        </form>
    </forms>
</config>

我在这里至少看到了一个类似的问题,但答案是要使用任务侦听器用于开始表格。我完全不确定它的作用方式,因为似乎启动任务不是 true任务,只能使用ExecutionListeners。差异应该很小,但是似乎在启动任务中对任务的任何引用都会导致失败或根本没有影响。因为我无法使用task.getVariableLocal()来获取值,所以我看不到要给execution.setVariable()赋予什么价值。

I have seen at least one question here that was similar, but the answers were stating to use task listeners for the start form. I'm not sure at all how that is intended to function, because it seems like a start task isn't a "true" task and can only use ExecutionListeners. The difference should be small, but it seems that any reference to "task" in the start task will either cause a failure or just have no affect at all. Becasue I can't use task.getVariableLocal() to get the value, I don't see what to give to execution.setVariable() as the value.

推荐答案

以我的经验,启动任务中各个方面和属性的所有值都将自动复制到executionContext中,并且可用于将来的任务。

In my experience, all values of aspects and properties in a start task are automatically copied to the executionContext and are already available for future tasks.

尝试删除BPMN中的执行侦听器,您不需要这样做。然后尝试在后续任务上执行starttasklistener,将值从执行上下文复制到此任务中。

Try removing the executionlistener in your BPMN, you shouldnt need that. Then try making a starttasklistener on your subsequent task that copyies the value from your execeutioncontext into this task. It should work fine.

在后续任务中从执行上下文中获取var应该像这样:

Getting the var back from your executioncontext in your subsequent task should work like this:

<activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener"> 
   <activiti:field name="language" stringValue="groovy" /
   <activiti:field name="script"> 
   <activiti:string><![CDATA[
   System.out.println(execution.getVariable("deliveryTicketWorkflow_requestdetailstext"));        
   if (execution.getVariable("deliveryTicketWorkflow_requestdetailstext") != null){
     task.setVariableLocal('deliveryTicketWorkflow_requestdetailstext', execution.getVariable("deliveryTicketWorkflow_requestdetailstext"));
    }]]>
   </activiti:string>
</activiti:field>
</activiti:taskListener>

这篇关于Activiti工作流程:从StartTask设置方面的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:16