Alfresco task listener variables

2019-09-02 05:38发布

I have two task listeners,the first on event="create" the second on event="complete". In the first i'm counting files when task was created, in the second when task completed and looking if the number of files is equal throw an error. But this not work, i have ReferenceError: "count" is not defined.

<extensionElements>
        <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
          <activiti:field name="script">
            <activiti:string><![CDATA[
               var count = 0;
               for (var i = 0; i < bpm_package.children.length; i++) 
                {
                  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[
               var count_new = 0;
               for (var i = 0; i < bpm_package.children.length; i++) 
                {
                  count_new++;
                }
                if (count ==count_new)
                 {
                    var message = "\n\nAdd files\n";
                    throw new Error(message + "\n");
                 }
    ]]></activiti:string>
          </activiti:field>
        </activiti:taskListener>
      </extensionElements>

2条回答
Anthone
2楼-- · 2019-09-02 06:06

I solved the problem of how to define a variable. You need to add execution.setVariable ('zvernennya_count', count); to the first task listener.

But it does not solve my problem of testing attachments, because the variable count is defined once, and the task has multi-user access, and when the first users task is completed, the next users task already has variable count_new different from count.

查看更多
祖国的老花朵
3楼-- · 2019-09-02 06:26

You are getting ReferenceError because that "count" variable is not visible to other Listener.

If you need to persist the value of variable you have to define variable in the workflow model use that variable in place of local variable count.

http://docs.alfresco.com/4.0/concepts/wf-task-model.html

This should give you good starting point.

查看更多
登录 后发表回答