2016-02-22 28 views
3

当我开始工作流程时,我需要将其分配给某人的选项。如果没有人被选中,我想默认将其分配给发起者。工作流程:为bpm设置默认值:受让人

这样做可能不会创建一个扩展bpm:受让人的新模型吗?如果不是,那么这个扩展将如何完成?

我相信杰夫波茨这个答案是相关的:https://stackoverflow.com/a/9418066/4542428

注:我使用的社区版4.2

编辑:Stefan的回答让我绝大多数的方式来回答,但似乎我以某种方式错误地引用了关联的值。背景:我从来没有使用关联,这可能只是我没有理解它们与类型和方面的区别。

从我的模型:

<type name="deliveryTicketWorkflow:start"> 
     <parent>bpm:startTask</parent> 
     <properties>  
     </properties> 
     <associations /> 
     <overrides /> 
     <mandatory-aspects> 
     <aspect>deliveryTicketWorkflow:pmAspect</aspect> 
     <aspect>deliveryTicketWorkflow:requestDetailsAspect</aspect> 
     </mandatory-aspects> 
</type> 
<aspect name="deliveryTicketWorkflow:pmAspect"> 
     <associations> 
      <association name="deliveryTicketWorkflow:assignedPM"> 
        <source> 
         <mandatory>false</mandatory> 
         <many>false</many> 
        </source> 
        <target> 
         <class>cm:person</class> 
         <mandatory>false</mandatory> 
         <many>true</many> 
        </target> 
       </association> 
     </associations> 
    </aspect> 

这是使用我的配置为:

<config condition="activiti$deliveryTicketWorkflow" evaluator="string-compare"> 
     <forms> 
      <form> 
       <field-visibility> 
... 
        <show id="deliveryTicketWorkflow:assignedPM" /> 
... 
       </field-visibility> 
       <appearance> 
... 
        <field id="deliveryTicketWorkflow:assignedPM" label-id="Project Manager" /> 
... 
       </appearance> 
      </form> 
     </forms> 
    </config> 

我对deliveryTicketworkflow配置:开始是相同的。这成功地显示了人员选择器,而不是强制性的,正如Stefan所说的那样,完全是100%。

在我的BPMN工作流定义,然后我有一个执行监听器,这些片段的启动事件:

  if(!execution.getVariable("deliveryTicketWorkflow_assignedPM")){ 
      execution.setVariable("deliveryTicketWorkflow_assignedPM", initiator); 
      } 
... 
     deliveryTicket.properties["dtdlm:projectManager"] = execution.getVariable("deliveryTicketWorkflow_assignedPM").properties.firstName + " " + execution.getVariable("deliveryTicketWorkflow_assignedPM").properties.lastName; 

当工作流运行,我选择谁作为PM,即最后一行(其中抓取PM的姓和名)返回“deliveryTicketWorkflow_assignedPM”未定义的值。当它留空时,一切都会顺利进行,但工作流程描述的“常规信息”部分仍将项目管理器列为(无)。

回答

4

您的确可以根据jeff描述的定制人员选取器,但它需要相当多的编码工作。

另外,您可以使用事件启动工作流executionlistener,并用它来bpm_assignee变量设置为启动的情况下,它是形式空:

添加监听到你bpmn20:

<activiti:executionListener event="start" class="com.mycomp.Executionlistener"></activiti:executionListener> 

在您的第一个使用任务中,将受让人定义为工作流开始表单中的关联属性。

<userTask id="firsttask" name="firsttask" activiti:assignee="${mymodel.myassoc.properties.userName}" > 

还将此关联添加到您的启动任务内容模型。在com.mycomp.Executionlistener

代码如下所示:

public void notify(DelegateExecution execution) throws Exception { 
    if (execution.getVariable("mymodel_myassoc") == null){ 

     ActivitiScriptNode userScriptNode= (ActivitiScriptNode) execution.getVariable("initiator"); 
     execution.setVariable("mymodel_myassoc",userScriptNode); 
    } 
} 
+0

这是一般的方法,我向倾斜,但我的印象是,你不能让工作流发射点下执行监听器没有填写所有必填字段(即bpm:受理人)。 –

+0

尝试在起始表单中为受让人使用自定义字段,并将其设置为非强制性。然后在你的bmp第一项任务中使用这个字段作为受让人。我已经更新了答案 –

+0

我认为这已经解决了我的问题,因为它在我离开选择器时变为空白,但是我做了一些非常错误的事情,从来没有真正引用选择器的值。更新原始问题并重新开放。 –