cancel
Showing results for 
Search instead for 
Did you mean: 

workflow percent refresh

ingon
Champ in-the-making
Champ in-the-making
Hi all,

I'm working on a workflow and have find some problems to make it work properly.

It works fine, but when I try to show the approval percentage in the workflow details it always displays 0 (zero).

Here is my code:

customworkflowmodel.xml:

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

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

   <imports>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
      <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>

   <namespaces>
      <namespace uri="http://www.alfresco.org/model/testworkflow/content/1.0" prefix="test" />
   </namespaces>

   <types>

      <type name="test:generateDraft">
         <parent>bpm:startTask</parent>
         <mandatory-aspects>
            <aspect>bpm:groupAssignee</aspect>
            <aspect>test:percents</aspect>
         </mandatory-aspects>
      </type>

      <type name="test:reviewTask">
         <parent>bpm:activitiOutcomeTask</parent>
         <properties>
            <property name="test:reviewTaskOutcome">
               <type>d:text</type>
               <default>Reject</default>
               <constraints>
                  <constraint name="test:reviewTaskOutcomeOption" type="LIST">
                     <parameter name="allowedValues">
                        <list>
                           <value>Approve</value>
                           <value>Reject</value>
                        </list>
                     </parameter>
                  </constraint>
               </constraints>
            </property>
         </properties>
      </type>

   </types>

   <aspects>

      <aspect name="test:percents">
         <properties>
            <property name="test:requiredApprovePercent">
               <type>d:int</type>
               <mandatory>true</mandatory>
               <default>100</default>
               <constraints>
                  <constraint type="MINMAX">
                     <parameter name="minValue">
                        <value>0</value>
                     </parameter>
                     <parameter name="maxValue">
                        <value>100</value>
                     </parameter>
                  </constraint>
               </constraints>
            </property>
            <property name="test:currentPercent">
               <type>d:int</type>
               <mandatory>true</mandatory>
               <default>0</default>
               <constraints>
                  <constraint type="MINMAX">
                     <parameter name="minValue">
                        <value>0</value>
                     </parameter>
                     <parameter name="maxValue">
                        <value>100</value>
                     </parameter>
                  </constraint>
               </constraints>
            </property>
         </properties>
      </aspect>

   </aspects>

</model>

processdefinition.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: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://alfresco.org">

   <process id="harmonization" name="Harmonizates test documents">

      <extensionElements>
         <activiti:executionListener event="start"
            class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
            <activiti:field name="script">
               <activiti:string>
                  var authNode = "";
                  var memberNames = new java.util.ArrayList();
                  for each (permission in bpm_package.children[0].permissions) {
                        var valuesList = permission.split(";");
                        if (valuesList[0].toUpperCase().indexOf("ALLOWED") >= 0) {
                           authNode = people.getGroup(valuesList[1]);
                           if (authNode != null) {
                              var cont = 0;
                              for each (member in people.getMembers(authNode, true)) {
                                 for (var i=0; i&lt;memberNames.size(); i++) {
                                    if ( memberNames.get(i) == member.properties.userName) {
                                       cont++;
                                    }
                                 }
                                 if (cont == 0) {
                                    memberNames.add(member.properties.userName);
                                 }
                              }
                           }
                        }
                     }
                     if (memberNames.size() == 0) {
                     logger.error("No group found");
                     }
                        execution.setVariable('testwf_approveCount', 0);
                          execution.setVariable('testwf_currentPercent', 0);
                          execution.setVariable('testwf_requiredApprovePercent', 100);
                          execution.setVariable('testwf_groupMembers', memberNames);
                        execution.setVariable('testwf_reviewerCount', memberNames.size());                          
                     </activiti:string>
            </activiti:field>
         </activiti:executionListener>
      </extensionElements>

      <startEvent id="start" activiti:formKey="testwf:generateDraft" />


      <sequenceFlow id='flow1' sourceRef='start' targetRef='reviewTask' />

      <userTask id="reviewTask" name="Review Task" activiti:formKey="testwf:reviewTask">
         <extensionElements>
            <activiti:taskListener event="complete"
               class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
               <activiti:field name="runAs">
                  <activiti:string>admin</activiti:string>
               </activiti:field>
               <activiti:field name="script">
                  <activiti:string>
                           if(task.getVariableLocal('testwf_reviewTaskOutcome') == 'Approve') {
                                var newApprovedCount = testwf_approveCount + 1;
                               var newApprovedPercentage = (newApprovedCount / testwf_reviewerCount) * 100;
                               execution.setVariable('testwf_approveCount', newApprovedCount);
                               execution.setVariable('testwf_currentPercent', newApprovedPercentage);
                              if (bpm_package.children[0].type.equals("{test.model}annexeFile")) {
                                 bpm_package.children[0].properties["test:annexeFileHarmonize"] = newApprovedPercentage;
                              }
                              if (bpm_package.children[0].type.equals("{test.model}bookFile")) {
                                 bpm_package.children[0].properties["test:bookFileHarmonize"] = newApprovedPercentage;
                              }
                              if (bpm_package.children[0].type.equals("{test.model}issueFile")) {
                                 bpm_package.children[0].properties["test:issueFileHarmonize"] = newApprovedPercentage;
                              }
                              bpm_package.children[0].save();                            
                     }
                        </activiti:string>
               </activiti:field>
            </activiti:taskListener>
         </extensionElements>

         <humanPerformer>
            <resourceAssignmentExpression>
               <formalExpression>${reviewAssignee}</formalExpression>
            </resourceAssignmentExpression>
         </humanPerformer>

         <multiInstanceLoopCharacteristics isSequential="false">
            <loopDataInputRef>testwf_groupMembers</loopDataInputRef>
            <inputDataItem name="reviewAssignee" />
            <completionCondition>${testwf_currentPercent >= testwf_requiredApprovePercent}</completionCondition>
         </multiInstanceLoopCharacteristics>
      </userTask>

      <sequenceFlow id='flow2' sourceRef='reviewTask' targetRef='reviewDecision' />

      <exclusiveGateway id="reviewDecision" name="Review Decision" />

      <sequenceFlow id='flow3' sourceRef='reviewDecision' targetRef='end'>
         <conditionExpression xsi:type="tFormalExpression">
            ${testwf_currentPercent >= testwf_requiredApprovePercent}
         </conditionExpression>
      </sequenceFlow>

      <sequenceFlow id='flow4' sourceRef='reviewDecision' targetRef='start' />

      <endEvent id="end" />

   </process>

   <!– Graphical representaion of diagram –>
   <bpmndi:BPMNDiagram id="BPMNDiagram_harmonization">
      <bpmndi:BPMNPlane bpmnElement="harmonization" id="BPMNPlane_harmonization">
         <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
            <omgdc:Bounds height="35" width="35" x="30" y="200"></omgdc:Bounds>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="reviewTask" id="BPMNShape_reviewTask">
            <omgdc:Bounds height="55" width="105" x="125" y="190"></omgdc:Bounds>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="reviewDecision" id="BPMNShape_reviewDecision">
            <omgdc:Bounds height="40" width="40" x="290" y="197"></omgdc:Bounds>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
            <omgdc:Bounds height="35" width="35" x="560" y="200"></omgdc:Bounds>
         </bpmndi:BPMNShape>
         <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
            <omgdi:waypoint x="65" y="217"></omgdi:waypoint>
            <omgdi:waypoint x="125" y="217"></omgdi:waypoint>
         </bpmndi:BPMNEdge>
         <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
            <omgdi:waypoint x="230" y="217"></omgdi:waypoint>
            <omgdi:waypoint x="290" y="217"></omgdi:waypoint>
         </bpmndi:BPMNEdge>
         <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
            <omgdi:waypoint x="330" y="217"></omgdi:waypoint>
            <omgdi:waypoint x="560" y="217"></omgdi:waypoint>
         </bpmndi:BPMNEdge>
         <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
            <omgdi:waypoint x="310" y="237"></omgdi:waypoint>
            <omgdi:waypoint x="310" y="324"></omgdi:waypoint>
            <omgdi:waypoint x="47" y="324"></omgdi:waypoint>
            <omgdi:waypoint x="47" y="235"></omgdi:waypoint>
         </bpmndi:BPMNEdge>
      </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>

</definitions>

share-config-custom.xml:

<alfresco-config>

   <config evaluator="string-compare" condition="activiti$harmonization">

      <forms>

         <form>

            <field-visibility>
               <show id="bpm:workflowDescription" />
               <show id="packageItems" />
            </field-visibility>

            <appearance>

               <set id="" appearance="title" label-id="workflow.set.general" />
               <set id="info" appearance="" template="/org/alfresco/components/form/2-column-set.ftl" />
               <set id="assignee" appearance="title" label-id="workflow.set.assignee" />
               <set id="items" appearance="title" label-id="workflow.set.items" />
               <set id="other" appearance="title" label-id="workflow.set.other" />

               <field id="bpm:workflowDescription" label-id="workflow.field.message">
                  <control template="/org/alfresco/components/form/controls/textarea.ftl">
                     <control-param name="style">width: 95%</control-param>
                  </control>
               </field>
               <field id="packageItems" set="items" />

            </appearance>

         </form>

      </forms>

   </config>
   
   <config evaluator="task-type" condition="testwf:generateDraft">

      <forms>

         <form id="workflow-details">
            <field-visibility>
               <show id="testwf:requiredApprovePercent" />
               <show id="testwf:currentPercent" />
            </field-visibility>
            <appearance>
               <set id="" appearance="title" label-id="workflow.set.workflow.more_info" />
            </appearance>
         </form>

      </forms>

   </config>   

   <config evaluator="task-type" condition="testwf:reviewTask">

      <forms>

         <form>

            <field-visibility>
               <show id="message" />
               <show id="taskOwner" />
               <show id="bpm:taskId" />
               <show id="packageItems" />
               <show id="testwf:reviewTaskOutcome" />
            </field-visibility>

            <appearance>

               <set id="" appearance="title" label-id="workflow.set.task.info" />
               <set id="info" appearance="" template="/org/alfresco/components/form/3-column-set.ftl" />
               <set id="items" appearance="title" label-id="workflow.set.items" />
               <set id="response" appearance="title" label-id="workflow.set.response" />

               <field id="message">
                  <control template="/org/alfresco/components/form/controls/info.ftl" />
               </field>
               <field id="taskOwner" set="info" />
               <field id="bpm:taskId" set="info">
                  <control template="/org/alfresco/components/form/controls/info.ftl" />
               </field>
               <field id="packageItems" set="items" />
               <field id="testwf:reviewTaskOutcome" label-id="workflow.field.outcome" set="response">
                  <control template="/org/alfresco/components/form/controls/workflow/activiti-transitions.ftl" />
               </field>

            </appearance>

         </form>

      </forms>

   </config>

</alfresco-config>

The field testwf:currentPercent in workflow-details always returns 0. But it does show the real value in the activiti console… ¿any ideas?

Thank you very much in advance!!
5 REPLIES 5

afaust
Legendary Innovator
Legendary Innovator
Hello,

after the initial start task has been completed (which is usually immediately when the workflow is started), you can't update its properties further via standard APIs. Since your actual percentage value will be based on a dynamic state, I'd advise you not to use properties and instead use a form filter / field processor on the Repository tier to generate a transient field percentage.

Regards
Axel

ingon
Champ in-the-making
Champ in-the-making
Hi Axel,

Finally I found it out and tried some other way to show the progress, changing the node properties. Thank you anyway Smiley Happy

icm76
Champ in-the-making
Champ in-the-making
could you, please, give an example - i am in the same situation and i would like to see one.

thank

ingon
Champ in-the-making
Champ in-the-making
sorry I didn't answer icm76, I've just seen this reply. Do you still need help?

barcoffin
Champ in-the-making
Champ in-the-making
Hi Ingon,

   i am also in the same situation!

Please, could you give me an example?

Thank