Alfresco check for adding files

2019-09-10 03:16发布

There is a review and approval workflow On the start forms are attached files and selected executors(Package Items and People selection). Then create a task is assigned to the previously selected executors. Each executor sees the task assigned to it, and file attachments.

I need to check for adding files. While the executor has not added a file it can not approve the task. I created the counter at the time of task creation taskListener event="create". He counts the files sent to the executor. Then I created another counter at the time of completion of the task taskListener event="complete", It also counts files. Then I compare these two counters and if they are equivalent It means that the executor does not attach files and he sees the error. But this method works only for the first executor who approved the task. The rest of the executors can already approve the task without adding files.

I do not know what the problem is.

Here's the code where I implemented it:

<userTask id="userTask5" name="Revies" activiti:assignee="${zvernennya_reviewnachassignee.properties.userName}" activiti:formKey="zvernennya:reviewnach">
      <documentation>Review task</documentation>
      <extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[
        if (typeof bpm_workflowDueDate != 'undefined') task.dueDate = bpm_workflowDueDate;
        if (typeof bpm_workflowPriority != 'undefined') task.priority = bpm_workflowPriority;;    
        var count=0;
        for (var i = 0; i < bpm_package.children.length; i++) 
        { 
        count++;
        }
        execution.setVariable ('count', count);
]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
        <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[
        if(task.getVariableLocal('zvernennya_reviewnachtransitions') == 'Approve') {
        execution.setVariable('zvernennya_reviewnachapprovalcount', zvernennya_reviewnachapprovalcount + 1);
        }   
                           var count_new=0;
                           for (var i = 0; i < bpm_package.children.length; i++) 
                           {  
                           count_new++;
                           }
                           if (count==count_new) {    
                                var message = "\n\nAttach files!!\n";
                                 throw new Error(message + "\n");
                            }   
]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="zvernennya_executers" activiti:elementVariable="zvernennya_reviewnachassignee">
        <completionCondition>${zvernennya_reviewnachapprovalcount &gt;= zvernennya_reviewnachrequiredapprovalcount}</completionCondition>
      </multiInstanceLoopCharacteristics>
    </userTask>

1条回答
够拽才男人
2楼-- · 2019-09-10 03:55

I think you need to re-initialize the variable "count" in the 2nd tasklistener ("complete"). like so:

var count = execution.getVariable ('count');
var count_new= bpm_package.children.length;
if (count==count_new) {    
   var message = "\n\nAttach files!!\n";
   throw new Error(message + "\n");
}  
查看更多
登录 后发表回答