cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow jumping usertask

magarcia_sm
Star Contributor
Star Contributor
Hi there

We are creating a very simple workflow that has a start event, an userTask of type wf:activityReviewTask and an end event. In the usertask we define a listener by using a script this way:


<userTask id="iniciar" name="Revisar JefeDpto" activiti:assignee="gestor" activiti:formKey="wf:activitiReviewTask">
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[var test = bpm_package;
var doc = test.children[0];
if(task.getVariableLocal('wf_reviewOutcome') == 'Approve') {
   doc.properties["hula:estado"]="Revision_Gerencia";
   doc.save();
  }
else
{
   doc.properties["hula:estado"]="Cancelado";
   doc.save();
}]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>



however when we launch the workflow, the workflow gets executed, because as we have introduced in the listener of the usertask if it does not get approved sets the property "estado" to "Cancelado",and the document gets this value in the property. But this is like if Alfresco runs the workflow, and the task but no assigns anything to the user, and neither waits for the user to approve or reject the task.

Any ideas about what could be wrong??

Thanks a lot in advance!!

6 REPLIES 6

darkredd
Star Contributor
Star Contributor
Hi,

Please attach you process definition as we cannot track where the issue is with such a snippet of the code. However, you would be far better off defining your own model which its task-types inherit the activiti task model types; in your case the "wf:activitiReviewTask". But then again, more code would be very helpful in order for us to further help you.

magarcia_sm
Star Contributor
Star Contributor
Hi DarkRedd

Here I pass you the code we are using

The process definition is in the file LuisWorkflow.bpmn.xml


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="aprobacionAgenda" name="Aprobacion Agenda" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="entrada"></sequenceFlow>
    <serviceTask id="entrada" name="Mover a Departamento" activiti:class="org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate">
      <extensionElements>
        <activiti:field name="script">
          <activiti:string><![CDATA[var test = bpm_package;
var doc = test.children[0];
var departamento = doc.properties["hula:departamento"];
doc.properties["hula:estado"]="Revision_Jefe_servicio";
doc.save();
var myNode = companyhome.childByNamePath("Departamentos Jefes/"+departamento);]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="flow2" sourceRef="entrada" targetRef="iniciar"></sequenceFlow>
    <userTask id="iniciar" name="Revisar JefeDpto" activiti:assignee="Jefe_Cardiologia1" activiti:formKey="wf:activitiReviewTask">
      <extensionElements>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[var test = bpm_package;
var doc = test.children[0];
if(task.getVariableLocal('wf_reviewOutcome') == 'Approve') {
   doc.properties["hula:estado"]="Revision_Gerencia";
   doc.save();
  }
else
{
   doc.properties["hula:estado"]="Cancelado";
   doc.save();
}]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
    </userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow3" sourceRef="iniciar" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_aprobacionAgenda">
    <bpmndi:BPMNPlane bpmnElement="aprobacionAgenda" id="BPMNPlane_aprobacionAgenda">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="6.0" y="37.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="entrada" id="BPMNShape_entrada">
        <omgdc:Bounds height="55.0" width="105.0" x="70.0" y="27.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="iniciar" id="BPMNShape_iniciar">
        <omgdc:Bounds height="55.0" width="105.0" x="250.0" y="27.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="490.0" y="37.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="41.0" y="54.0"></omgdi:waypoint>
        <omgdi:waypoint x="70.0" y="54.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="175.0" y="54.0"></omgdi:waypoint>
        <omgdi:waypoint x="250.0" y="54.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="355.0" y="54.0"></omgdi:waypoint>
        <omgdi:waypoint x="490.0" y="54.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


and the workflow model is in LuisWorkflowModel.xml


<?xml version="1.0" encoding="UTF-8"?>

<model name="scwf:workflowmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

    <!– Optional meta-data about the model –>
    <description>Workflow Lifecycle Model</description>
    <author>smveritas</author>
    <version>1.0</version>

    <!– Imports are required to allow references to definitions in other models –>
    <imports>
        <!– Import Alfresco Dictionary Definitions –>
        <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
        <!– Import Alfresco Content Domain Model Definitions –>
        <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
        <import uri="http://www.alfresco.org/model/bpm/1.0" prefix="bpm" />
    </imports>
   
    <!– Introduction of new namespaces defined by this model –>
    <namespaces>
        <namespace uri="workflowmodel.model" prefix="scwf" />
    </namespaces>

    <types>
        <type name="scwf:activitiReviewTask">
         <parent>bpm:activitiOutcomeTask</parent>
         <properties>
            <property name="scwf:AprobarResp">
               <type>d:text</type>
               <default>Reject</default>
               <constraints>
                  <constraint type="LIST">
                     <parameter name="allowedValues">
                        <list>
                           <value>Aprobar</value>
                           <value>Rechazar</value>
                        </list>
                     </parameter>
                  </constraint>
               </constraints>
            </property>
            <property name="scwf:AprobarOT">
               <type>d:text</type>
               <default>Reject</default>
               <constraints>
                  <constraint type="LIST">
                     <parameter name="allowedValues">
                        <list>
                           <value>Aprobar</value>
                           <value>Rechazar</value>
                        </list>
                     </parameter>
                  </constraint>
               </constraints>
            </property>
         </properties>
      </type>
    </types>
</model>



As you can see the task to approve the document or not is in the UserTask with id="iniciar", however the workflow runs all the process in a row… not assigning any task to the asignee user neither waiting for anybody to approve or reject the task.

Any ideas please??


Thanks a lot in advance!!

Hi Margacia,

Your startEvent task is missing its formkey like this:
<startEvent id="startevent1" name="Start" activiti:formKey="bpm:startTask"></startEvent>
.

I am guessing the engine could not recognize the bpmn as a tasked workflow without that "formKey". That was your mistake.

Hope this helps.

Thank you very much DarkRedd
That was the problem, solved!

arak
Confirmed Champ
Confirmed Champ
Thanks, with your solution, I solved the same problem.

Then, is mandatory to add a form element in the start element of a workflow?

Greetings,
Pablo.

jlabuelo
Champ on-the-rise
Champ on-the-rise
Hi there

We have the same issue, however it is quite strange as we are using the Activitii plugin for Eclipse Keppler, and we use a "Alfresco Start Task" from the pallette of tasks in the right column of the diagram….. strange that this is not already included in the Alfresco Start Task.

Anyway, thanks a lot for your reply, solved me a day of work checking why is not launching my workflow!