问题
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.
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.
I am using Alfresco 4.2.f Community edition.
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>
The relevant parts of my model are:
<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>
In the config:
<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>
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.
回答1:
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.
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.
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>
回答2:
This is a long shot but in your share form, your custom field is using the info control:
I believe you need there to be a regular field there, the info field is to display text, AFAIK, it doesn't include an input field and won't send anything to the workflow start.
来源:https://stackoverflow.com/questions/35017229/activiti-workflow-setting-value-of-an-aspect-from-starttask