AnsweredAssumed Answered

Testing for an Alfresco association in order to select a workflow path

Question asked by amargosian on Jun 6, 2013
Latest reply on Jun 10, 2013 by frederikheremans1
Greetings!

This is my first post here, and I'm also new to Activiti (as well as Alfresco), so hopefully this will be a very easy question for you veterans!

I'm using Alfresco Enterprise with Activiti. I'm trying to set up a workflow where a user can initiate a workflow, assign either a single group or multiple individual users (by name), and the workflow will behave accordingly. In essence, I'm trying to combine the Activiti-delivered 'parallel review' and 'pooled review' workflows, with a decision point after the start task to decide which model to follow.

The examples delivered with the product use the Alfresco aspects "bpm:assignees" and "bpm:groupAssignee" to handle the assignments in the start task, but I can't leverage these directly, since I obviously can't set both as mandatory aspects when I want the user to pick one or the other. The problem is, I can't figure out how to test whether either or both of these associations is populated in order to set a flag through the listener. (I would then use that flag to choose a path from the decision point.)

In the sample code below, I'm trying to do this using task.getVariable, but it's not working. (I'm using typeof below; I've also tried this a few different ways.) Is there a different method I need to invoke?

By the way, I realize there are other problems with the code below, but I'm focusing specifically on this problem for now–once the forking is working the way I want it to, I'll flesh out the rest!

Thanks for your help!

********** BPMN definition *********

<?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: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="ecm809h" name="ECM-809-H" isExecutable="true">

        <extensionElements>
            <activiti:executionListener event="start" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
           <activiti:field name="script">
                     <activiti:string>
                          execution.setVariable('wf_sendToUser', 'false');
                          execution.setVariable('wf_sendToGroup', 'false');
                     </activiti:string>
                  </activiti:field>
            </activiti:executionListener>
        </extensionElements>
   
    <startEvent id="startevent1" name="Start" activiti:initiator="${initiator.properties.userName}" activiti:formKey="edtrmwf:coordinationWfStart">
   <extensionElements>
           <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
             <activiti:field name="script">
               <activiti:string>
                  
                  if (typeof task.getVariable('edtrmwf_groupAssignee') != 'undefined') {
                     execution.setVariable('edtrmwf_groupAssignee', task.getVariable('edtrmwf_groupAssignee'));
                     execution.setVariable('wf_sendToGroup', 'true');
                  }   
                  else
                     execution.setVariable('edtrmwf_groupAssignee', 'null');
                  
                  if (typeof task.getVariable('edtrmwf_assignees') != 'undefined') {
                     execution.setVariable('edtrmwf_assignees', task.getVariable('edtrmwf_assignees'));
                     execution.setVariable('wf_sendToUser', 'true');
      }
                  else
                     execution.setVariable('edtrmwf_assignees', 'null');           
   
      </activiti:string>
             </activiti:field>
           </activiti:taskListener>
   </extensionElements>
   
    </startEvent>
   
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
   
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="exclusivegateway1"></sequenceFlow>
   
    <userTask id="usertask1" name="User Task" activiti:formKey="edtrmwf:coordinateTaskUser"></userTask>
   
    <sequenceFlow id="flow2" sourceRef="exclusivegateway1" targetRef="usertask1">
       <conditionExpression xsi:type="tFormalExpression"><![CDATA[${wf_sendToUser == 'true'}]]></conditionExpression>
    </sequenceFlow>
   
    <userTask id="usertask2" name="Group Task" activiti:formKey="edtrmwf:coordinateTaskGroup"></userTask>
   
    <sequenceFlow id="flow3" sourceRef="exclusivegateway1" targetRef="usertask2">
       <conditionExpression xsi:type="tFormalExpression"><![CDATA[${wf_sendToGroup == 'true'}]]></conditionExpression>
    </sequenceFlow>
   
    <endEvent id="endevent1" name="End"></endEvent>
   
    <sequenceFlow id="flow4" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
   
    <sequenceFlow id="flow5" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
 
  </process>
 
  <bpmndi:BPMNDiagram id="BPMNDiagram_ecm809h">
    <bpmndi:BPMNPlane bpmnElement="ecm809h" id="BPMNPlane_ecm809h">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="160.0" y="260.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
        <omgdc:Bounds height="40.0" width="40.0" x="260.0" y="257.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55.0" width="105.0" x="400.0" y="190.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
        <omgdc:Bounds height="55.0" width="105.0" x="400.0" y="320.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="610.0" y="260.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="195.0" y="277.0"></omgdi:waypoint>
        <omgdi:waypoint x="260.0" y="277.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="280.0" y="257.0"></omgdi:waypoint>
        <omgdi:waypoint x="280.0" y="217.0"></omgdi:waypoint>
        <omgdi:waypoint x="400.0" y="217.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="280.0" y="297.0"></omgdi:waypoint>
        <omgdi:waypoint x="280.0" y="347.0"></omgdi:waypoint>
        <omgdi:waypoint x="400.0" y="347.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="505.0" y="217.0"></omgdi:waypoint>
        <omgdi:waypoint x="627.0" y="217.0"></omgdi:waypoint>
        <omgdi:waypoint x="627.0" y="260.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="505.0" y="347.0"></omgdi:waypoint>
        <omgdi:waypoint x="627.0" y="347.0"></omgdi:waypoint>
        <omgdi:waypoint x="627.0" y="295.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

**************** And the associated type from my Alfresco content model ************

      <type name="edtrmwf:coordinationWfStart">
         <title>Coordination Start</title>

          <parent>bpm:startTask</parent>
           
           <properties>  
              <!– decide how many people have to approve (all) –>
               <property name="edtrmwf:requiredApprovePercent">
                   <type>d:int</type>
                   <protected>true</protected>
                   <default>100</default>
                   <constraints>
                       <constraint type="MINMAX">
                           <parameter name="minValue"><value>1</value></parameter>
                           <parameter name="maxValue"><value>100</value></parameter>
                       </constraint>
                   </constraints>
               </property>
              
               <!– apm decide where task is going –>
            <property name="edtrmwf:sendToGroup">
                  <type>d:boolean</type>
                  <default>false</default>
                  <!– apm probably need to add bpm:groupassignee(s) as mandatory aspect –>
               </property>
              
               <property name="edtrmwf:sendToUser">
                  <type>d:boolean</type>
                  <default>false</default>
                  <!– apm probably need to add bpm:assignees as mandatory aspect –>
               </property>
              
          </properties>
            
             <!– apm associations cribbed from bpm:assignees and bpm:groupAssignee in order to avoid making both aspects mandatory –>
       <associations>

                <association name="edtrmwf:assignees">
                    <source>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </source>
                    <target>
                        <class>cm:person</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>

                <association name="edtrmwf:groupAssignee">
                    <source>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </source>
                    <target>
                        <class>cm:authorityContainer</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>

             </associations>


</type>

Outcomes